Ral*_*lph 8 java tomcat jndi javax.mail
我花了几天的时间来弄清楚如何通过JNDI在Tomcat中配置javax.mail.Session并进行身份验证,现在我得到了它,但只是在深入研究代码之后.
在这段时间里,我看到了有史以来最糟糕的代码:javax.mail.Service #connect(String,String,String,String)Version 1.4.1
if (user == null) {
user = url.getUsername();
if (password == null) // get password too if we need it
password = url.getPassword();
} else {
if (password == null && user.equals(url.getUsername()))
// only get the password if it matches the username
password = url.getPassword();
}
Run Code Online (Sandbox Code Playgroud)
密码何时分配?为什么两次检查null? - 然后意识到其他不属于如果以上.(这是原始的缩进).回到主题.
至少我发现正确的资源定义是:
<Resource name="email/session"
type="javax.mail.Session"
auth="Container"
password="secret"
mail.debug="false"
mail.transport.protocol="smtp"
mail.smtp.auth="true"
mail.smtp.user="testi"
mail.smtp.host="smtp.xxx.org"
mail.smtp.from="test@example.com"
/>
Run Code Online (Sandbox Code Playgroud)
请注意它是"password"和"mail.smtp.user"或"mail.user"但不是"mail.smtp.password"或"user".
至少神奇是在雄猫队完成的org.apache.naming.factory.MailSessionFactory.javax.mail.Authenticator如果属性password和属性mail.smtp.user或mail.user退出,此工厂将添加到邮件会话.
现在我的问题是所有这些东西的文档在哪里.特别是关于用户名和密码的配置?
顺便说一句:我解释得更详细一些,以帮助其他人如何解决同样的问题.
| 归档时间: |
|
| 查看次数: |
4200 次 |
| 最近记录: |