今天写了邮件相关的api,小小的总结一下。先来了解一下邮件发送的过程,一封邮件发出,先发送到你的邮件服务器上,由你的邮件服务器发送到目标邮件服务器,再由目标邮件服务器转发到目标地址,区别于点对点传输。
javamail封装了邮件操作的基本类,利用javamail来实现邮件发送,要先下载mail.jar包,加到项目中,jdk版本要在1.6及以上。下面例子结合了struts框架,来看下例子:
public String sendMail() {//发送邮件(action中的方法)
try{
ActionContext actionContext = ActionContext.getContext();
Map<String, Object> session = actionContext.getSession();
Mail umail=(Mail) session.get("user");
Authenticator auth = new SmtpAuthenticator( umail.getUsername(), umail.getPassword());
Properties mailProps = new Properties();
//用户校验
mailProps.put("mail.smtp.auth", "true");
//启用ssl
mailProps.put("mail.smtp.ssl.enable", "true");
//设置端口号
mailProps.put("mail.smtp.port", "
javamail封装了邮件操作的基本类,利用javamail来实现邮件发送,要先下载mail.jar包,加到项目中,jdk版本要在1.6及以上。下面例子结合了struts框架,来看下例子:
public String sendMail() {//发送邮件(action中的方法)
try{
ActionContext actionContext = ActionContext.getContext();
Map<String, Object> session = actionContext.getSession();
Mail umail=(Mail) session.get("user");
Authenticator auth = new SmtpAuthenticator( umail.getUsername(), umail.getPassword());
Properties mailProps = new Properties();
//用户校验
mailProps.put("mail.smtp.auth", "true");
//启用ssl
mailProps.put("mail.smtp.ssl.enable", "true");
//设置端口号
mailProps.put("mail.smtp.port", "