sendMailSession=Session.getInstance(props);
改成:
Authenticator auth = new PopupAuthenticator();
sendMailSession=Session.getInstance(props,auth);//class PopupAuthenticator
public class PopupAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username, password;
username = "";
password = "";
return new PasswordAuthentication(username, password);
}
}
改成:
Authenticator auth = new PopupAuthenticator();
sendMailSession=Session.getInstance(props,auth);//class PopupAuthenticator
public class PopupAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username, password;
username = "";
password = "";
return new PasswordAuthentication(username, password);
}
}
HtmlEmail email=new HtmlEmail();
email.setHostName(smtp host); email.setAuthentication(用户名, 用户密码); email.addTo(接收认EMAIL地址,接收人名字); email.setFrom(发送人EMAIL地址,发送人名字); email.setSubject(MimeUtility.encodeText(主题,"GBK","B"));
email.setCharset("GBK");
email.setHtmlMsg(邮件内容);
email.send();