Java 郵件收發類庫,Commons Email 1.4 發布

c5fr 9年前發布 | 11K 次閱讀 Commons Email

Commons Email 1.4 發布了,該項目是Apache的Commons子項目下的一個電子郵件收發類庫,基于JavaMail實現,大大簡化了郵件的收發操作。主要類包括:

  • 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.
  • ImageHtmlEmail - This class is used to send HTML formatted emails with inline images. It has all of the capabilities as HtmlEmail but transform all image references to inline 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.                     
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();

與 1.3.3 版本比較主要改進包括如下幾個方面:

== Compatibility ==

* Java 5 or later is required (unchanged since 1.3).

* JavaMail dependency has been upgraded to version 1.5.2,
  as a consequence, the maven dependency has changed to:

  <dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>1.5.2</version>
  </dependency>

== New Features ==

* Added getter for the bounce address of an email to class Email.
  Issue: EMAIL-146. Thanks to Alexander Lehmann.

* Added support for mapping of content-ids to DataSource in "MimeMessageParser".
  Issue: EMAIL-141. Thanks to Stephen Kruger.

== Updates ==

* Update Oracle JavaMail dependency from 1.4.5 to 1.5.2.
  Issue: EMAIL-144.

== Fixed Bugs ==

* "Email" threw an "EmailException" when trying to send the email if neither a from
  nor bounce address was specified, although a "mail.from" property was set in the mail session.
  Issue: EMAIL-149. Thanks to Richard DiCroce.

* "ImageHtmlEmail" failed to embed attachments if their data source name was null.
  Issue: EMAIL-151. Thanks to Andreas Kohn.

* Html emails did not have the correct content-type set when using the Apache Geronimo
  JavaMail implementation v1.8.x.
  Issue: EMAIL-147. Thanks to Can Eskikaya.

* An "HtmlEmail" with both, an html and plain text content but no attachments or embedded
  images will now be created with mimetype "multipart/alternative" instead of "multipart/mixed".
  Issue: EMAIL-142. Thanks to Marcin Tomiak.

 本文由用戶 c5fr 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!