簡化Java 收發郵件的類庫,Commons Email 1.3.1 發布

jopen 11年前發布 | 10K 次閱讀 Commons Email

該項目是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();

Commons Email 發布了 1.3.1 更新版本,該版本要求 Java 5 或者更新版本支持,同時修復了兩個bug:

* DataSourceClassPathResolver will now correctly set the DataSource name for resolved
  resources. Additionally, it is now possible to set the name for a ByteArrayDataSource.
  Issue: EMAIL-125.

* Header values are not folded twice anymore. The actual encoding and folding is
  now only performed in Email.buildMimeMessage().
  Issue: EMAIL-124. 
 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!