我公司的客户即将升级我们软件的版本。在他的升级测试环境中,他发现他不能再通过应用程序发送邮件了(他没有改变他的SMTP服务器的配置,这与他在生产环境中使用的一切都很好)。
我们通过测试发现这个“错误”是由将javax.mail jar从版本1.3.1更改为1.5.2版本的升级引起的。为了验证这一点,我们给客户端一个.class来执行发送电子邮件,如果它使用1.3.1版本的javax.mail jar,它可以工作,但如果它使用1.5.2版本,它不会工作。客户端将服务器配置写入属性文件。
mail.smtp.host=<ip_adress>
mail.smtp.port=25
mail.from=clientCompany@clientDomain
mail.to=recipient@clientDomain
mail.smtp.user=clientCompany@clientDomain
mail.smtp.password=<client_pwd>
mail.subject=whatever
mail.body=whatever
Properties systemProperties = System.getProperties();
systemProperties.putAll(fileProperties);
Session mailSession = Session.getDefaultInstance(systemProperties);
Transport tr = mailSession.getTransport("smtp");
tr.connect(mailSmtpHost, Integer.valueOf(mailSmtpPort), mailSmtpUser, mailSmtpPassword);
tr.sendMessage(mailToSend, mailToSend.getAllRecipients());
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,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
...
DEBUG SMTP: trying to connect to host "<ip_adress>", port 25, isSSL false
...
DEBUG SMTP: connected to host "<ip_adress>", port: 25
...
DEBUG SMTP: Found extension "SIZE", arg "37748736"
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 "XRDST", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: NTLM
DEBUG NTLM: type 1 message: 4E 54 4C 4D 53 53 50 00 01 00 00 00 03 B2 00 00 0A 00 0A 00 2E 00 00 00 0E 00 0E 00 20 00 00 00 50 42 54 4B 41 50 4D 4F 42 49 4C 45 30 31 42 54 4B 44 2E 4C 4F 43 41 4C
DEBUG SMTP: AUTH NTLM command trace suppressed
DEBUG NTLM: type 3 message: 4E 54 4C 4D 53 53 50 00 03 00 00 00 18 00 18 00 9E 00 00 00 18 00 18 00 B6 00 00 00 14 00 14 00 40 00 00 00 2E 00 2E 00 54 00 00 00 1C 00 1C 00 82 00 00 00 00 00 00 00 CE 00 00 00 01 82 00 00 42 00 54 00 4B 00 44 00 2E 00 4C 00 4F 00 43 00 41 00 4C 00 65 00 62 00 61 00 6E 00 6B 00 69 00 6E 00 67 00 2D 00 62 00 74 00 6B 00 40 00 62 00 74 00 6B 00 6E 00 65 00 74 00 2E 00 63 00 6F 00 6D 00 50 00 42 00 54 00 4B 00 41 00 50 00 4D 00 4F 00 42 00 49 00 4C 00 45 00 30 00 31 00 1F F4 4F 84 82 68 AD 69 9E D3 84 53 11 98 FE 72 78 06 75 79 03 E4 04 6F A5 F5 FA E5 F7 B0 E5 98 CD 25 20 B5 10 04 B9 64 B5 A8 2E 2F D9 C5 64 B7
DEBUG SMTP: AUTH NTLM failed
javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:892)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:814)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:728)
at javax.mail.Service.connect(Service.java:364)
at MailSendTest.sendMail(MailSendTest.java:87)
at MailSendTest.main(MailSendTest.java:132)
DEBUG: java.io.FileNotFoundException: /opt/java64/jdk1.6.0_30/jre/lib/javamail.providers (No such file or directory)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,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: {imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,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: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: /opt/java64/jdk1.6.0_30/jre/lib/javamail.address.map (No such file or directory)
...
DEBUG SMTP: trying to connect to host "<ip_adress>", port 25
...
DEBUG SMTP: connected to host "<ip_adress>", port: 25
...
DEBUG SMTP: Found extension "SIZE", arg "37748736"
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 "XRDST", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: use8bit false
MAIL FROM:<clientCompany@clientDomain>
250 2.1.0 Sender OK
RCPT TO:<recipient@clientDomain>
250 2.1.5 Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP: recipient@clientDomain
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Message-ID: <181398600.1528806707522.JavaMail.clientCompany@clientDomain>
From: clientCompany@clientDomain
To: recipient@clientDomain
Subject: whatever
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_1199604121.1528806707440"
------=_Part_0_1199604121.1528806707440
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
whatever
------=_Part_0_1199604121.1528806707440--
当我尝试使用带有javax.mail 1.5.2的.class和我公司的SMTP服务器配置时,它可以工作。我无法重现他们的错误。所以我们猜测它可能来自他们的邮件服务器。
我阅读了有关此问题的多个主题但尚未找到任何解决方案。可能是将端口从25更改为587,这是推荐的端口,但我真的不明白为什么它会改变任何东西(加上它在我的计算机上使用25或587)。