添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am currently evaluating Jodd-Mail and it looks good so far. I can successfully send mails to a dummy SMTP server (Papercut). However, when I switched to the SmtpSslServer, things started to become more difficult. I try to establish a connection with the SMTP Server:

SmtpSslServer server = new SmtpSslServer("example.com", 587
    .authenticateWith("username", "password")
    .startTlsRequired(true);
server.debug(true);
session = server.createSession();
session.open();

But the debug output looks like the following:

DEBUG: JavaMail version 1.5.6
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: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=example.com, user=windows_username, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "example.com", port 587, isSSL false
jodd.mail.MailException: Failed to connect; <--- javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

As you can see, the debug output states that the used username is "windows_username" (which I substituted for my real windows username) and the used password is null, despite the fact that I specified a password in the code above.

Is Jodd-Mail simply not compatible with JavaMail 1.5.6 or am I using it incorrect?

Thanks in advance!

Tobias

Hi @tobiasrodehutskors !

It is interesting problem, but I doubt it is because of new version of Java mail. It looks more that you are trying to do an SSL connection to a non-SSL port. I guess you want to use SSL, right? However, the code returns:

trying to connect to host "example.com", port 587, isSSL false

It also seems you are using hotmail or outlook, these should help:

mail.smtp.starttls.enable=true 
mail.smtp.port=587

however, Jodd should set these.

Would you be so kind to tell me if you want to use SSL or not?

Thanks for your fast response!

Yes, I want to use SSL, hence my usage of SmtpSslServer instead of SmtpServer. Unfortunatly, I am not using a public mail server, but I was able to reproduce the issue on a public server.

First of all, you are right that this has nothing to do with the new Java Mail version 1.5.6, as I was able to send mails using Jodd-Mail through a GMail account using port 465:

DEBUG: JavaMail version 1.5.6
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: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=smtp.gmail.com, user=<my windows username>, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 smtp.gmail.com ESMTP f10sm37739552wje.14 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO 10.16.64.122
250-smtp.gmail.com at your service, [195.37.61.178]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: STARTTLS requested but already using SSL
DEBUG SMTP: protocolConnect login, host=smtp.gmail.com, user=<my gmail account>, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
221 2.0.0 closing connection f10sm37739552wje.14 - gsmtp

What I find puzzling in this output is, that it first mentions that SSL is off:

DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false

But later on mentions that it is already using SSL:

DEBUG SMTP: STARTTLS requested but already using SSL

However, this is not the real problem I am encountering. But as soon as I switch to use port 587 (which is also allowed according to Google), I get the following debug output, all with the same code as in my original post:

DEBUG: JavaMail version 1.5.6
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: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=smtp.gmail.com, user=<my windows username>, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
[de.rcenvironment.core.mail.internal.MailServiceImpl] : Unable to contact mail server.
jodd.mail.MailException: Failed to connect; <--- javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

This is the same debug output as in my first post. What puzzels me here and also in the previous debug ouputs it the fact, that an SMTP provider is used:

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]

But I expect that an SMTP_S_ provider is used, since I am using the SmtpSslServer. Is this assumption wrong?

Tobias

I just had a look at some of the closed issues and came across #210, which solves my problem. I just need to set plaintextOverTLS:

SmtpSslServer server = new SmtpSslServer("example.com", 587
    .authenticateWith("username", "password")
    .startTlsRequired(true)
    .plaintextOverTLS(true);
server.debug(true);
session = server.createSession();
session.open();

This is somehow confusing from my point of view. Is there any reason to specify startTlsRequired(true) but not also specifiying plaintextOverTLS(true)? I think this should be set implicitly if startTlsRequired is true.

Tobias

There is no special reason, Jodd was just keeping the defaults behind the scene... Do you think startTlsRequired should always require plaintextOverTLS? I was under impression it is optional.

But now when I think about it... we do provide plaintext with authenticateWith so it totally make sense to have this set to true.

Do you maybe know how to send username/pass not using the plain text?

Hey @tobiasrodehutskors I could not find anywhere that one requires the other. I haven't found anything in the docs that says that one requires the other.

It looks to me that plaintextOverTLS may be set by default when using SmtpSslServer. What do you think?

SO question