Java Mail Microsoft Exchange NTLM

时间:2013-05-01 11:04:01

标签: java spring smtp ntlm

我在网上搜索过,但找不到有效的解决方案。我收到以下例外:

Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful

以下是我的输出:

JavaMail version 1.4.3
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc],  com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun  Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider [STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
 DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
 DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
 DEBUG SMTP: useEhlo true, useAuth true
 DEBUG SMTP: trying to connect to host "NB-EX10-1.example.com", port 25, isSSL false
220 NB-EX10-1.example.com Microsoft ESMTP MAIL Service ready at Wed, 1 May 2013 11:48:32 +0100
DEBUG SMTP: connected to host "NB-EX10-1.example.com", port: 25

EHLO PC-9MF9LP1.example.com
250-NB-example.com Hello [192.168.22.123]
250-SIZE
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-X-ANONYMOUSTLS
250-AUTH NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250-XRDST
250 XSHADOW
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "X-ANONYMOUSTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "NTLM"
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "XEXCH50", arg ""
DEBUG SMTP: Found extension "XRDST", arg ""
DEBUG SMTP: Found extension "XSHADOW", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
DEBUG SMTP: mechanism LOGIN not supported by server
DEBUG SMTP: mechanism PLAIN not supported by server
DEBUG SMTP: mechanism DIGEST-MD5 not supported by server
DEBUG NTLM: type 1 message: suppliedWorkstation: PC-9MF9LP1.example.com
DEBUG NTLM: type 1 message length: 61
AUTH NTLM TlRMTVNTUAABAAAAACAAAAAAAAA9AAAAHQAdACAAAABQQy05TUY5TFAxLk5FVEJVSUxERVIuUFJJVkFURQ==
535 5.7.3 Authentication unsuccessful
Exception : Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful

我使用Spring 3.0来使用JavaMail API,如下所示:

<bean id="mailSenderBean" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="NB-EX10-1.example.com"></property> <!-- localhost-->
    <property name="username" value="myusername"></property>
    <property name="password" value="password"></property>
    <property name="javaMailProperties">
        <props>
            <prop key="mail.smtp.port">25</prop>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.starttls.enable">false</prop>
            <prop key="mail.transport.protocol">smtp</prop>
            <!-- <prop key="mail.smtp.auth.ntlm.domain"></prop>-->
            <prop key="mail.debug">true</prop>
        </props>
    </property>
</bean>

我们正在使用Microsoft Exchange Server 2010.我只需要使用NTLM进行连接。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题,发现“mail.smtp.port”应该是 587 因为当电子邮件客户端或外发服务器提交一封电子邮件以供适当的邮件服务器路由时,它应该始终使用 SMTP 端口 587 作为默认端口。