问题描述
当我尝试在Web应用程序中使用java邮件api发送邮件时,出现此异常.
when im trying to send a mail using java mail api in my web application , I'm getting this exception.
java.lang.SecurityException:无法访问默认会话
java.lang.SecurityException: Access to default session denied
输入来自html页面.然后转到一个servlet,该servlet最终调用一个Java类,在其中编写邮件逻辑
the inputs are fron an html page. then it goes to a servlet which eventually calls a java class where the mail logic is written
推荐答案
此错误文本与对Session.getDefaultInstance(props, authenticator)
的调用相关联,其中默认实例已设置了不同的身份验证器.
This error text is associated with a call to Session.getDefaultInstance(props, authenticator)
where the default instance already has a different authenticator set.
如果您在代码中调用Session.getInstance(props, authenticator)
而不是Session.getDefaultInstance(props, authenticator)
,效果会更好.
It should work better if you call Session.getInstance(props, authenticator)
instead of Session.getDefaultInstance(props, authenticator)
in your code.
这篇关于java mail api:抛出异常,并说java.lang.SecurityException:拒绝访问默认会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!