java发送邮件时遇到异常:java.lang.SecurityException:Access to default session denied在自己的机器weblogic上部署能够发送,但是部署到集群后发送邮件时会报该异常发送邮件时报错!java.lang.SecurityException:Acce
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/08 17:46:49
java发送邮件时遇到异常:java.lang.SecurityException:Access to default session denied在自己的机器weblogic上部署能够发送,但是部署到集群后发送邮件时会报该异常发送邮件时报错!java.lang.SecurityException:Acce
java发送邮件时遇到异常:java.lang.SecurityException:Access to default session denied
在自己的机器weblogic上部署能够发送,但是部署到集群后发送邮件时会报该异常
发送邮件时报错!
java.lang.SecurityException:Access to default session denied
at javax.mail.Session.getDefaultInstance(Session.java:321)
at com.geostar.util.mail.SimpleMailSender.sendHtmlMail(SimpleMailSender.java:75)
at com.geostar.geoglobe.usercenter.action.userinfo_tb.Userinfo_tbAction.sendMail(Userinfo_tbAction.java:342)
at com.geostar.geoglobe.usercenter.action.userinfo_tb.Userinfo_tbAction.saveUser_name(Userinfo_tbAction.java:271)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
...
java发送邮件时遇到异常:java.lang.SecurityException:Access to default session denied在自己的机器weblogic上部署能够发送,但是部署到集群后发送邮件时会报该异常发送邮件时报错!java.lang.SecurityException:Acce
Session.getDefaultInstance()是获得一个默认的共享session,而创建一个session可以使用Session.getInstance().
所以将程序改写成这样就OK了.
Properties props = System.getProperties();
props.put("mail.host",Globals.MAIL_SERVER);
props.put("mail.smtp.auth","true");
Session session1 = Session.getInstance(props,new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(Globals.MAIL_USERNAME,Globals.MAIL_PASSWORD);
}});