简化Java 收发邮件的类库,Commons Email 1.3.1 发布

jopen 11年前

该项目是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.