我写了一个发送邮件的小程序,在测试时,发信人和收信人都是用的我自己的邮箱。结果没有收到正确的信息,而是一封如下所示的信:
发信人:postmaster@xuyan
收信人:[email protected]
主题:Delivery Status Notification (Failure)
内容:
This is an automatically generated Delivery Status Notification.Delivery to the following recipients failed. [email protected]
发信人:postmaster@xuyan
收信人:[email protected]
主题:Delivery Status Notification (Failure)
内容:
This is an automatically generated Delivery Status Notification.Delivery to the following recipients failed. [email protected]
import javax.mail.PasswordAuthentication;public class MyAuthenticator extends javax.mail.Authenticator {
private String strUser;
private String strPwd;
public MyAuthenticator(String user, String password) {
this.strUser = user;
this.strPwd = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(strUser, strPwd);
}
}使用:
MyAuthenticator myauth = new MyAuthenticator("username", "password");
Session session = Session.getInstance(props, myauth);