簡體   English   中英

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.usermail.user退出,則該工廠將javax.mail.Authenticator添加到郵件會話。

現在我的問題是所有這些東西的文檔在哪里。 特別是關於用戶名和密碼的配置?

順便說一句:我解釋得更詳細一些,以幫助其他人遇到同樣的問題。

這只是文檔中的錯誤。 有人已經在Tomcat Bug Tracker上提出了這個問題

https://bz.apache.org/bugzilla/show_bug.cgi?id=53665

我建議您注冊該錯誤並對其投票。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM