Jakarta commons-Email 1.0 is released.
Commons-Email provides a set of simpler email operation APIs.
Commons-email is built based on the javamail API. The core structure only contains a few classes.
The following is a brief introduction to some of the classes:
Simpleemail-This class is used to send basic text based emails.
Multipartemail-This class is used to send multipart messages. This allows a text message with attachments either inline or attached.
Htmlemail-This class is used to send HTML formatted emails. It has all of the capabilities as multipartemail allowing attachments to be easily added. It also supports embedded images.
Emailattachment-this is a simple container class to allow for easy handling of attachments. it is for use with instances of multipartemail and htmlemail. commons-email is an open-source API provided by Apache and is an encapsulation of javamail. Therefore, javamail must be used. jar is added to the class path, including simpleemail, multipartemail, htmlemail, and emailattachment.
Simpleemail: send a simple email and do not add attachments.
Multipartemail: Text mail. You can add multiple attachments.
Htmlemail: HTML-formatted mail with all "functions" of the multipartemail class"
Emailattchment: attachment class. You can add local resources or specify network resources. Resources on the network are automatically downloaded and sent upon sending.
Send emails in basic text format:
====================
Simpleemail email = new simpleemail ();
// SMTP host
Email. sethostname ("mail.test.com ");
// User name and password used to log on to the email server
Email. setauthentication ("test", "testpassword ");
// Recipient
Email. addto ("jdoe@somewhere.org", "John Doe ");
// Sender
Email. setfrom ("me@apache.org", "me ");
// Title
Email. setsubject ("Test message ");
// Email content
Email. setmsg ("this is a simple test of commons-email ");
// Send
Email. Send (); text format, with attachment Email:
============================
// Attachment. Multiple attachment objects can be defined.
Emailattachment attachment = new emailattachment ();
Attachment. setpath ("E: // 1.20 ");
Attachment. setdisposition (emailattachment. Attachment );
Attachment. setdescription ("picture of John ");
//
Multipartemail email = new multipartemail ();
// SMTP host
Email. sethostname ("mail.test.com ");
// User name and password used to log on to the email server
Email. setauthentication ("test", "testpassword ");
// Recipient
Email. addto ("jdoe@somewhere.org", "John Doe ");
// Sender
Email. setfrom ("me@apache.org", "me ");
// Title
Email. setsubject ("Test message ");
// Email content
Email. setmsg ("this is a simple test of commons-email ");
// Add an attachment
Email. Attach (Attachment );
// Send
Email. Send ();
Send an email with an attachment in HTML format:
========================
// Attachment. Multiple attachment objects can be defined.
Emailattachment attachment = new emailattachment ();
Attachment. setpath ("E: // 1.20 ");
Attachment. setdisposition (emailattachment. Attachment );
Attachment. setdescription ("picture of John ");
//
Htmlemail email = new htmlemail ();
// SMTP host
Email. sethostname ("mail.test.com ");
// User name and password used to log on to the email server
Email. setauthentication ("test", "testpassword ");
// Recipient
Email. addto ("jdoe@somewhere.org", "John Doe ");
// Sender
Email. setfrom ("me@apache.org", "me ");
// Title
Email. setsubject ("Test message ");
// Email content
Email. sethtmlmsg ("<B> This is a simple test of commons-email </B> ");
// Add an attachment
Email. Attach (Attachment );
// Send
Email. Send ();