早教吧作业答案频道 -->其他-->
java发送邮件时遇到异常:java.lang.SecurityException:Accesstodefaultsessiondenied在自己的机器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)
...
在自己的机器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)
...
▼优质解答
答案和解析
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);
}});
所以将程序改写成这样就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);
}});
看了 java发送邮件时遇到异常:...的网友还看了以下:
已知f(x)是定义在[-e,e]上的奇函数,当x€(0.e](€是属于符号)时,f(x)=e^x+ 2020-05-13 …
数学分析习题.设函数f(x)在[a,b]上三阶可导,证明:存在一点e∈(a,b)设函数f(x)在[ 2020-07-16 …
f(x),g(x),h(x)在[a,b]上连续,(a,b)上可导,求证存在一个e属于(a,b)使得 2020-07-16 …
问一道数学题,科大上p175我这样做的:(1)将等式两边求导:1=f`*e^f+f*e^f*f`= 2020-07-18 …
已知函数f(x)=alnx+x2(a为实常数).(1)当a=-4时,求函数f(x)在[1,e]上已 2020-07-27 …
实变函数设f是点集E上的可测函数且存在两个函数g,h满足g∈L(E)h∈L(E)及g(x)≤f(x 2020-07-30 …
正方形的6个面分别写着A、B、C、D、E、F,与B、C、E相对的分别是哪个面?F在上面图一上F,前 2020-07-31 …
已知函数f(x)是定义在[-e,0)∪(0,e]上的奇函数,当x∈(0,e],f(x)=ax+㏑x 2020-08-01 …
EXCEL循环或计算问题。F=A+B+C+D+E。(A.B.C.D.E.F.均要大于零)E=A*10 2020-11-01 …
一个数学定义不理解,学过数学分析的朋友请帮助我.称w(f;E):=sup|f(x1)-f(x2)|为 2020-11-27 …