Tomcat中JNDI的Java Mail API配置文档 [英] Documentation of Java Mail API configuration for JNDI in Tomcat
问题描述
我花了几天时间弄清楚如何通过JNDI 带有身份验证在Tomcat中配置javax.mail.Session. >
这一次,我看到了有史以来最糟糕的代码:javax.mail.Service#connect(String,String,String,String)版本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();
}
何时分配密码?为什么要对null进行两次检查? –然后意识到else不属于上述if. (这是原始缩进).返回主题.
至少我发现正确的资源定义是:
<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"
/>
请注意,它是"password"和"mail.smtp.user"或"mail.user",而不是"mail.smtp.password"或"user".
至少魔术是在Tomcats org.apache.naming.factory.MailSessionFactory
中完成的.如果属性password
和属性mail.smtp.user
或mail.user
退出,则工厂将javax.mail.Authenticator
添加到邮件会话中.
现在我的问题是所有这些东西的文档在哪里.尤其是关于用户名和密码的配置?
顺便说一句:我对它进行了详细解释,以帮助其他人遇到同样的问题.
Tomcat文档是受限制的,但是源代码在这里: Pay attention to the fact that it is „password" and „mail.smtp.user" or „mail.user" but not „mail.smtp.password" or "user". At least the magic is done in Tomcats Now my question is where is the documentation for all that stuff. Especially about configuration of username and password? Btw: I explained it a bit more detailed to help other how has the same problem. Tomcat documentation is limited but the source code is here: http://javasourcecode.org/html/open-source/tomcat/tomcat-7.0.19/org/apache/naming/factory/MailSessionFactory.java.html 这篇关于Tomcat中JNDI的Java Mail API配置文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!org.apache.naming.factory.MailSessionFactory
. This factory add an javax.mail.Authenticator
to the mail session if an property password
and an property mail.smtp.user
or mail.user
exits.