需要的JAR包:
Commons-Email-x.x.jar
mail-x.x.jar
activation-x.x.jar (注:如果是JDK1.6,就可以不需要这个了)
commons-email 用户指南
[url]http://commons.apache.org/email/userguide.html[/url]
下面只是一个简单的邮件发送。
Commons-Email-x.x.jar
mail-x.x.jar
activation-x.x.jar (注:如果是JDK1.6,就可以不需要这个了)
commons-email 用户指南
[url]http://commons.apache.org/email/userguide.html[/url]
下面只是一个简单的邮件发送。
package com.common.email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
public class CommonEmailMain {
public static void main(String[] args) throws EmailException {
SimpleEmail email = new SimpleEmail();
email.setHostName("smtp.sina.com");//邮件服务器
//smtp认证的用户名和密码
email.setAuthentication("username@sina.com", "password");
email.addTo("receiverName@sina.com", "receiver");//收信者
email.setFrom("userName@sina.com", "Rowen");//发信者
email.setSubject("userName测试邮件");//标题
email.setCharset("UTF-8");//编码格式
email.setMsg("您好,这是一个测试邮件");//内容
email.send();
}
}