用commons-email-1.2.jar实现发邮件功能
从http://commons.apache.org/email/download_email.cgi下载最新的Common Email,版本1.2。
?
?
TestCommonEMail类
?
package org.mail.test;import org.apache.commons.mail.EmailAttachment;import org.apache.commons.mail.EmailException;import org.apache.commons.mail.MultiPartEmail;import org.apache.commons.mail.SimpleEmail;public class TestCommonEMail {public static void main(String[] args) {MultiPartEmail email = new MultiPartEmail();email.setHostName("smtp.qq.com");// 设置使用发电子邮件的邮件服务器 smtp.163.comtry {email.addTo("收件人信箱", "收件人别名");email.setAuthentication("发件人信箱", "发件人信箱密码");//smtp认证的用户名和密码email.setFrom("发件人信箱", "发件人别名");//写的信箱要与设置使用发电子邮件的邮件服务器相对应email.setSubject("Test apache.commons.mail message");//标题email.setMsg("This is a simple test of commons-email");//内容EmailAttachment emailattachment = new EmailAttachment();emailattachment.setPath("love.jpg");//放到工程下email.attach(emailattachment);email.send();} catch (EmailException ex) {ex.printStackTrace();}}}???