Commons Email 1.3.2 发布了,该项目是Apache的Commons子项目下的一个邮件客户端组件,它是基于JavaMail的,大大简化了邮件的收发操作。
该版本改进记录包括:
- Change visibility of DataSourceUrlResourceResolver.createUrl(String) to protected so that sub-classes can override it. Fixes EMAIL-135.
- Support default mime charset property "mail.mime.charset" when adding text content to instances of either SimpleEmail or HtmlEmail. Fixes EMAIL-104
- Added support for sending partial emails in case of invalid addresses. Fixes EMAIL-132. Thanks to Allen Xudong Cheng.
- The MimeMessageParser will now correctly parse MIME multi-parts of type "text/plain" and "text/html" with a content disposition header of "attachment". The parts will be added to the list of attachments even if there is no other text or html content. Fixes EMAIL-131.
- Special characters in the body of an HTML email could lead to an exception when the mime message was built. Fixes EMAIL-127. Thanks to Dominik Stadler.
示例代码:
01 |
Email email = new SimpleEmail(); |
02 |
email.setHostName("smtp.googlemail.com"); |
03 |
email.setSmtpPort(465); |
04 |
email.setAuthenticator(new DefaultAuthenticator("username", "password")); |
05 |
email.setSSLOnConnect(true); |
06 |
email.setFrom("user@gmail.com"); |
07 |
email.setSubject("TestMail"); |
08 |
email.setMsg("This is a test mail ... :-)"); |
09 |
email.addTo("foo@bar.com"); |
JavaDoc: http://commons.apache.org/email/apidocs/index.html
Commons Email 的下载地址:请点这里
