These advantages include being able to set various values such as some header fields like the X-Mailer, Content-Type and Message-Id.
There are two beans that I have played with so far. The first one has been mentioned on this forum and is a one-part sequence for sending. It's a "quick-and-simple" bean called EZSMTP and can be purchased for $35.00. You can find it here. (NOTE: As of June 2004 it seems that EZJavabeans has vanished off the web, I suggest using the ElegantJ beans anyway because of their feature set)
http://www.ezjavabeans.com/
The other email bean I have worked with is from ElegantJBeans. The bean is the SMTPClient bean and it's broken down into two parts for sending - meaning you need two beans (derived from the one smtpclient.jar file) added to your form . It's included as part of the Networking collection (which is quite cool because you get other beans for FTP, HTTP, POP3, SMTP, MIME, Server, Server Socket, Datagram packet & Datagram socket). However, the price for the ElegantJBeans Networking beans is $149.00. You can find them here.
http://www.elegantjbeans.com/network/
The following code below will get you started for sending email with either of these SMTP bean solutions.
EZSMTP ADVANTAGES
- You can set message priority
- You can set the HELO command (controlling who the server thinks is sending)
- Supports HTML content
- Control over the timeout setting for server connections
- Single bean required
ELEGANT SMTPClient ADVANTAGES
- Ability to set X-Mailer header
- Ability to set Organization header
- Ability to change Date header
- Ability to set Message-Id header
- Ability to set Mime version header
- Full Content-Type control
- You can set the encoding for emails (Content-Transfer-Encoding)
- Base 64 encoding function
- Save sent messages (although you could do this with a method)
- read/write external files for sending
MISSING FEATURES
- Ability to control any header (Reply-To and others)
EZSMTP CODE
NOTE: You'll need to change the ".bean_337" to whatever id is assigned to the bean you add to your form!
- Code: Select all
var m = elements.bean_337 //Create an object within a variable
m.authLogin = true //Set true/false if authorization is required
m.username = 'username'; //Set Username
m.password = '******'; //Set login password
m.mailServer = 'mail.server.com'; //Set the mail server
m.multipleSend = false; //Set true for keeping a connection open
m.subject = 'This is the subject line'; //Set the subject of the email
m.from = 'from@domain.com'; //Set the from for the email
m.to = 'to@domain.com'; //Set the to address(es)
//m.cc = 'cc@domain.com'; //Optional cc
//m.bcc = 'bcc@domain.com'; //Optional bcc
m.body = 'This is the email body'; //Set the body of the email
m.htmlContent = false; //Set the content to HTML or plain
m.sendMail() //Send the email
ELEGANT J BEANS SMTPClient CODE
NOTE: You'll need to change the ".bean_51" and ".bean_166" to whatever id is assigned to the beans you add to your form! There are two beans that need to be added to your form.
- Code: Select all
/* The first step is to create a MIME compliant message */
var m = elements.bean_51; //First we need to create the MIME email
m.from = 'from@domain.com'; //Set the FROM property
m.to = 'to@domain.com'; //Set the TO property (Use comma for multiples)
m.subject = 'Subject line is elegant'; //Set the SUBJECT property
m.body = 'This is the body'; //Set the BODY property
//m.cc = 'cc@domain.com'; //Set the CC property
//m.bcc = 'bcc@domain.com'; //Set the BCC property
m.organization = 'My Company'; //Optional ORGANIZATION header field
m.XMailer = 'My Mailer'; //Optional XMailer header field
m.contentType = 'text/plain; charset="use-ascii"; format=flowed'; //See RFC 2822
/* The second step is to open a connection to the SMTP server and send */
var s = elements.bean_166;
s.authentication = true;
s.hostName = 'mail.server.com';
s.userName = 'username';
s.password = '*******';
s.openConnection();
s.sendMail(m); //We pass the message object from var m into the send
globals.testing = elements.bean_166.getStatus();//Capture the reply from the server into a global
elements.bean_166.closeConnection(); //Close the connection to the server
Closing comments: There are a number of features in either bean that I would like to see consolidated into one "comprehensive bean". The ability to control the HELO and any header field would be desirable. I also found that setting some of the properties in the ElegantJBean stay persistant. Meaning if you set the BCC field for one record but then do another send, you need to make sure and clear this value by setting it to an empty value - otherwise you might BCC someone on an email you didn't intend for them.
Getting a server response is much easier from the ElegantJBean as you can use the .getStatus() function. Without knowing how to implement a java listener into Servoy, getting a reply from the server is much harder with the EZSMTP bean. Maybe someone with more bean knowledge will know how to return the results of a listener into a field.
Hope this information makes it easier for you to learn about working with beans and sending email!