1。
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;public class MailAuthenticator extends Authenticator {
public MailAuthenticator() {
} private String mUser;
private String mPass; public MailAuthenticator(String userName, String passWord) {
super();
mUser = userName;
mPass = passWord;
} protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mUser, mPass);
}}Session s=Session.getInstance(props);//根据属性新建一个邮件会话
改成:
Session.getInstance(
props,
(Authenticator)new MailAuthenticator(userId, userPass)); public boolean sendmail(Message mailmsg) throws Exception { if (this.getSession() == null) {
logger.debug("session是空的");
} this.getSession().getTransport("smtp").send(mailmsg);
this.getSession().getTransport("smtp").close();
return true;
/*
}
catch (Exception ex) {
logger.debug(this.getUserId() + "发送邮件失败了" +
System.currentTimeMillis());
ex.printStackTrace();
logger.debug("error",ex);
}*/
// return false;
} /**
* test
*/
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;public class MailAuthenticator extends Authenticator {
public MailAuthenticator() {
} private String mUser;
private String mPass; public MailAuthenticator(String userName, String passWord) {
super();
mUser = userName;
mPass = passWord;
} protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mUser, mPass);
}}Session s=Session.getInstance(props);//根据属性新建一个邮件会话
改成:
Session.getInstance(
props,
(Authenticator)new MailAuthenticator(userId, userPass)); public boolean sendmail(Message mailmsg) throws Exception { if (this.getSession() == null) {
logger.debug("session是空的");
} this.getSession().getTransport("smtp").send(mailmsg);
this.getSession().getTransport("smtp").close();
return true;
/*
}
catch (Exception ex) {
logger.debug(this.getUserId() + "发送邮件失败了" +
System.currentTimeMillis());
ex.printStackTrace();
logger.debug("error",ex);
}*/
// return false;
} /**
* test
*/
我设置的服务器是qzsoft.cn
为什么只有[email protected]的邮件能发送其它的则不行呢如163,126等