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
*/
解决方案 »
- java调用console程序打开文件的问题
- spring的拦截器(MethodInterceptor)做权限验证,怎么判断session里是否有值
- extjs tree双击获得返回值
- 线程中的空指针异常
- SSH开发中权限系统的设计
- Entity的自动创建表问题。
- 郁闷:在“Generating Artifacts”期间发生了内部错误。
- 项目构建工具和管理管理工具,大家都用什么?
- jsp 页面表格Excel导出 “automation服务器不能创建对象”错误
- QQ:13628198 怎么看tomcat的启动信息.不知道这里有没有对tomcat理解比较透的牛人. Email:[email protected]
- 用什么方法可以使写得很乱的JSP文件自动调整对齐?
- 请教大虾!!
我设置的服务器是qzsoft.cn
为什么只有[email protected]的邮件能发送其它的则不行呢如163,126等