Tomcat中JNDI的Java Mail API配置文档

编程入门 行业动态 更新时间:2024-10-13 20:13:50
本文介绍了Tomcat中JNDI的Java Mail API配置文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我花了几天时间弄清楚如何通过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" mail.smtp.from="test@example" />

请注意,它是"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文档是受限制的,但是源代码在这里: javasourcecode/html/open-source/tomcat/tomcat-7.0.19/org/apache/naming/factory/MailSessionFactory.java.html

I spend several days to figure out how to configure an javax.mail.Session in Tomcat via JNDI with authentication, now I get it but only after a deep dive in the code.

In this time I have seen the worst code ever: 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(); }

When is the password assigned? and why is it checked against null twice? – and then realize that the else does not belong to the if above. (This is the original indentation). Back to topic.

At least I found that the correct resource definition is:

<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" mail.smtp.from="test@example" />

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 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.

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: javasourcecode/html/open-source/tomcat/tomcat-7.0.19/org/apache/naming/factory/MailSessionFactory.java.html

更多推荐

Tomcat中JNDI的Java Mail API配置文档

本文发布于:2023-10-26 18:26:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文档   JNDI   Tomcat   Java   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!