import java.util.Date;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
public class TestMail {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.163.com");
email.setAuthentication("xxx@163.com", "xxx密码");
try {
email.addTo("xxx@qq.com", "小明");
email.setSentDate(new Date());
email.setSmtpPort(25);
email.setFrom("xxx@163.com", "小红");
email.setSubject("请吃饭");
email.setHtmlMsg("请吃饭");
email.setCharset("utf-8");
email.send();
System.out.println("发送邮件成功");
} catch (EmailException e) {
e.printStackTrace();
}
}
}
jar
commons-email-1.2.jar
Mail.jar