-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Gunnar Hillert opened SPR-12294 and commented
Even though mail.smtp.auth is set to false, it looks like that setting the username and password property on JavaMailSenderImpl may cause issues. (The JavaDoc for the respective setters indicates otherwise)
This may not be a bug per se but the current handling feels problematic (user-experience). The following configuration for example throws an exception:
<bean class="org.springframework.mail.javamail.JavaMailSenderImpl" id="mailSender">
<property name="host" value="${mail.smtp.host}"/>
<property name="port" value="${mail.smtp.port}"/>
<property name="username" value="${mail.user.id}"/>
<property name="password" value="${mail.user.password}"/>
<property name="javaMailProperties">
<props>
<prop key="mail.debug">${mail.debugEnabled}</prop>
<prop key="mail.smtp.auth">${mail.authenticationEnabled}</prop>
</props>
</property>
</bean>
Using the following properties:
mail.authenticationEnabled=false
mail.user.id=
mail.user.password=
Resulting in the following error:
DEBUG: JavaMail version 1.4.4
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 false
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
220 server1.ajug.org ESMTP Postfix (Ubuntu)^M
DEBUG SMTP: connected to host "localhost", port: 25
EHLO server1^M
250-server1.ajug.org^M
250-PIPELINING^M
250-SIZE 10240000^M
250-VRFY^M
250-ETRN^M
250-STARTTLS^M
250-AUTH PLAIN LOGIN^M
250-AUTH=PLAIN LOGIN^M
250-ENHANCEDSTATUSCODES^M
250-8BITMIME^M
250 DSN^M
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10240000"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "AUTH=PLAIN", arg "LOGIN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
AUTH LOGIN^M
334 VXNlcm5hbWU6^M
^M
334 UGFzc3dvcmQ6^M
^M
535 5.7.8 Error: authentication failed: generic failure^M
2014-10-03 00:32:45,976 ERROR | task-scheduler-6 | | | org.springframework.integration.handler.LoggingHandler | [Payload MessageHandlingException content=org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.mail.MailSendingMessageHandler#0]][Headers={id=7366cd24-8a16-82cb-06bd-644fb7b526b8, timestamp=1412310765976}] |
If I remove:
<property name="username" value="${mail.user.id}"/>
<property name="password" value="${mail.user.password}"/>
Everything works.
<bean class="org.springframework.mail.javamail.JavaMailSenderImpl" id="mailSender">
<property name="host" value="${mail.smtp.host}"/>
<property name="port" value="${mail.smtp.port}"/>
<property name="javaMailProperties">
<props>
<prop key="mail.debug">${mail.debugEnabled}</prop>
<prop key="mail.smtp.auth">${mail.authenticationEnabled}</prop>
</props>
</property>
</bean>
Therefore, would it be better to set empty String params to null for setUsername and setPasswords? Or check more explicitly for whether mail.smtp.auth is true or false?
I found an unanswered forum posting from 2008 that describes the same issue.
http://forum.spring.io/forum/spring-projects/container/44657-possible-bug-in-javamailsenderimpl-auth
Affects: 4.0.7
Reference URL: http://forum.spring.io/forum/spring-projects/container/44657-possible-bug-in-javamailsenderimpl-auth
Issue Links:
- JavaMailSender.doSend() should more aggressively catch exceptions [SPR-12298] #16904 JavaMailSender.doSend() should more aggressively catch exceptions
Referenced from: commits cc02269