Javamail and STARTTLS not working on different platforms - jakarta-mail

I created an example to send emails using STARTLS. Running it on 3 different windows versions hosted in different domains, everything works.
The bizzare thing is that when I run it on a Ubuntu Server 14.02 LTS it doesn't works. There is no firewall blocking and the java application binaries are the same.
This is the code:
// Port we will connect to on the Amazon SES SMTP endpoint. We are choosing port 25 because we will use
// STARTTLS to encrypt the connection.
static final int PORT = 25;
public static void main(String[] args) throws Exception {
// Create a Properties object to contain connection configuration information.
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", PORT);
// Set properties indicating that we want to use STARTTLS to encrypt the connection.
// The SMTP session will begin on an unencrypted connection, and then the client
// will issue a STARTTLS command to upgrade to an encrypted connection.
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.ssl.enable", "false");
props.put("mail.debug", "true");
// Create a Session object to represent a mail session with the specified properties.
Session session = Session.getDefaultInstance(props);
// Create a message with the specified information.
MimeMessage msg = new MimeMessage(session);
msg.setReplyTo(InternetAddress.parse("no-reply#no-host.com"));
msg.setFrom(new InternetAddress(FROM));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
msg.setSubject(SUBJECT);
msg.setContent(BODY, "html/plain");
// Create a transport.
Transport transport = session.getTransport("smtp");
// Send the message.
try {
System.out.println("Attempting to send an email through the Amazon SES SMTP interface...");
// Connect to Amazon SES using the SMTP username and password you specified above.
transport.connect(HOST, PORT, SMTP_USERNAME, SMTP_PASSWORD);
// Send the email.
transport.sendMessage(msg, msg.getAllRecipients());
System.out.println("Email sent!");
} catch (Exception ex) {
System.out.println("The email was not sent.");
System.out.println("Error message: " + ex.getMessage());
} finally {
// Close and terminate the connection.
transport.close();
}
}
This is the javamail log from a Windows environment (what is working):
DEBUG: JavaMail version 1.5.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,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]
Attempting to send an email through the Amazon SES SMTP interface...
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "email-smtp.us-west-2.amazonaws.com", port 25, isSSL false
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-1207632523 H3nxFSQJ7ktEpHBHuT38
DEBUG SMTP: connected to host "email-smtp.us-west-2.amazonaws.com", port: 25
EHLO roberton
250-email-smtp.amazonaws.com
250-8BITMIME
250-SIZE 10485760
250-STARTTLS
250-AUTH PLAIN LOGIN
250 Ok
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10485760"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "Ok", arg ""
STARTTLS
220 Ready to start TLS
EHLO xxxxxxxxxxxxxxxx
250-email-smtp.amazonaws.com
250-8BITMIME
250-SIZE 10485760
250-STARTTLS
250-AUTH PLAIN LOGIN
250 Ok
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10485760"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "Ok", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<naoresponder#xxxxxxxxx>
250 Ok
RCPT TO:<xxxxxxxxxxxxxxxxxxxxx>
250 Ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP: xxxxxxxxxxxxxxx
DATA
354 End data with <CR><LF>.<CR><LF>
From: xxxxxxxxxxxxxx
Reply-To: xxxxxxxxxxxxx
To: xxxxxxxxxxxxxxxxxxx
Message-ID: <1926764753.0.1448359358140#xxxxxxxx>
Subject: Amazon SES test (SMTP interface accessed using Java)
MIME-Version: 1.0
Content-Type: html/plain
Content-Transfer-Encoding: 7bit
This email was sent through the Amazon SES SMTP interface by using Java.
.
250 Ok 0000015138f203b5-6fcd5424-60c3-43eb-9542-83699cf36c46-000000
DEBUG SMTP: message successfully delivered to mail server
Email sent!
QUIT
221 Bye
And this is the log from the Ubuntu (environment what isn't working):
DEBUG: JavaMail version 1.5.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,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]
Attempting to send an email through the Amazon SES SMTP interface...
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "email-smtp.us-west-2.amazonaws.com", port 25, isSSL false
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-1207632523 tIUsmWGoY4gXLCMWdUpi
DEBUG SMTP: connected to host "email-smtp.us-west-2.amazonaws.com", port: 25
EHLO xxxxxxxxx
250-email-smtp.amazonaws.com
250-8BITMIME
250-SIZE 10485760
250-AUTH PLAIN LOGIN
250 Ok
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10485760"
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "Ok", arg ""
DEBUG SMTP: STARTTLS required but not supported
The email was not sent.
Error message: STARTTLS is required but host does not support STARTTLS
This is the callstack error:
javax.mail.MessagingException: STARTTLS is required but host does not support STARTTLS
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:719)
at javax.mail.Service.connect(Service.java:364)
at SESEmail.main(SESEmail.java:64)
Java version: 1.8.0_60-b27
Why this is happening?

I was using an official example from AWS SES http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-java.html , and this one was using port smtp 25 for TLS.
For some reason, this port (25) doesn't works with TLS in some of my enviroments.
After some research, I found this http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-connect.html and tried to use the default TLS port 587, and now it works in both of my environments (linux and windows).
I think this was a problem/behavior from AWS SES servers and not a Java Mail problem. I will try to report this for AWS team.

Related

Relay access denied Error in PostFix

I am using digitalocean mailing server. I have configured Mail_In_box in Ubuntu 14 version and also map my domain registrar DNS with server. I have installed roundcude mail and also able to send and receive email using roundcude and it is working nice.
Now I am trying to send email using javamail. But each time, I am getting error 554 5.7.1 : Relay access denied Below is my log.
DEBUG SMTP: trying to connect to host "mail.domainname.com", port 587, isSSL false
220 mail.domainname.com ESMTP Hi, I'm a Mail-in-a-Box (Ubuntu/Postfix; see https://mailinabox.email/)
DEBUG SMTP: connected to host "mail.domainname.com", port: 587
EHLO admin.lan
250-mail.domainname.com
250-PIPELINING
250-SIZE 134217728
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "134217728"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<myfirstemailaddress#domainname.com>
250 2.1.0 Ok
RCPT TO:<myemailaddress#gmail.com>
554 5.7.1 <myemailaddress#gmail.com>: Relay access denied
DEBUG SMTP: Invalid Addresses
DEBUG SMTP: myemailaddress#gmail.com
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 2.0.0 Ok
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <myemailaddress#gmail.com>: Relay access denied
main.cf file:
mydestination = #myhostname, localhost.$myhostname, localhost
mynetworks = 127.0.0.0/8 $myhostname [::ffff:127.0.0.0]/104 [::1]/128
Kindly help me.

How to use DIGEST-MD5 with Javamail

My application sends emails using Javamail. In order to authenticate with the email server I currently have to store the password somewhere in the application configuration files. I'd like to avoid this, providing at least a bit of security by storing only a hash of the password.
According to the wikipedia article http://en.wikipedia.org/wiki/Digest_access_authentication I should be able to achieve this by using DIGEST-MD5 authentication, which allows the application to authenticate using only an MD5 hash of the username:realm:password instead of needing to know the cleartext password.
I can't find any clear example on how to use DIGEST-MD5 in Javamail. I see some references to a class com.sun.mail.smtp.DigestMD5 but this doesn't exist in the latest javamail package and I can't find any explanation why.
The code below is as far as I could get with it. The email is sent successfully but the debug output seems to indicate it is still using PLAIN authentication through SASL, even though I've specified that DIGEST-MD5 is the only mechanism allowed.
Beyond that, I'm still specifying the plaintext password as an argument to the transport.connect method, whereas I want to be providing the hashed username:realm:password instead.
Can anyone point me to a working example of using DIGEST-MD5 with Javamail? Thanks!
Code below, with try/catch blocks removed...
Properties properties=new Properties();
properties.put("mail.smtp.starttls.enable","true");
properties.put("mail.smtp.timeout",3000); // 3 second timeout establishing connection
properties.put("mail.smtp.auth.mechanisms","DIGEST-MD5");
Session session=Session.getInstance(properties);
session.setDebug(true);
Message message=new MimeMessage(session);
message.setFrom(constructAddress(myGmailAddress,"my name"));
message.addRecipient(Message.RecipientType.TO,constructAddress(recipientEmailAddress,"Recipient Name"));
message.setSubject("test email");
message.setText("...");
SMTPTransport transport=(SMTPTransport)session.getTransport("smtp");
transport.setSASLEnabled(true);
transport.setSASLRealm("gmail.com");
transport.connect("smtp.gmail.com",587,myGmailAddress,password);
transport.sendMessage(message,message.getAllRecipients());
transport.close();
Here's the (truncated) debug output:
DEBUG: setDebug: JavaMail version 1.5.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 mx.google.com ESMTP pb7sm87689296pac.10 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587
EHLO laptop-mj
250-mx.google.com at your service, [(my ip address)]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO laptop-mj
250-mx.google.com at your service, [(my ip address)]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Authenticate with SASL
DEBUG SMTP: SASL AUTH command trace suppressed
DEBUG SMTP: SASL Mechanisms:
DEBUG SMTP: LOGIN
DEBUG SMTP: PLAIN
DEBUG SMTP: XOAUTH
DEBUG SMTP: XOAUTH2
DEBUG SMTP: PLAIN-CLIENTTOKEN
DEBUG SMTP:
DEBUG SMTP: SASL callback length: 2
DEBUG SMTP: SASL callback 0: javax.security.auth.callback.NameCallback#55f6efd2
DEBUG SMTP: SASL callback 1: javax.security.auth.callback.PasswordCallback#46faf015
DEBUG SMTP: SASL client PLAIN
DEBUG SMTP: use8bit false
MAIL FROM:<(my gmail address)>
250 2.1.0 OK pb7sm87689296pac.10 - gsmtp
... continues on with successful email transmission
DIGEST-MD5 allows the server to not store the password, but the client still needs the password. The main advantage is that the password is never sent in clear text to the server.
If the server supported DIGEST-MD5 (Gmail doesn't appear to), you use it just like any other authentication, supplying the password to the connect method.

IMAP using OAuth2 on App Engine

I'm trying to implement a service on App Engine that interacts with an Gmail account using OAuth2, Java 7 and App Engine SDK 1.8.2. The problem being encountered is via the use of sample code provided by https://code.google.com/p/google-mail-oauth2-tools/wiki/JavaSampleCode the Security provider does not appear to be detected on a node although works locally fine. The code provided by the link before has been modified to be initiated by a servlet with sample code:
import java.io.IOException;
import java.security.Provider;
import java.security.Security;
import java.util.Properties;
import javax.mail.Session;
import javax.mail.URLName;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.code.samples.oauth2.OAuth2SaslClientFactory;
import com.sun.mail.imap.IMAPSSLStore;
import com.sun.mail.imap.IMAPStore;
import com.sun.mail.smtp.SMTPTransport;
public class RunnerServlet extends HttpServlet
{
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
{
String email = request.getParameter( "email");
String oauthToken = request.getParameter( "oauthToken");
initialize();
try
{
IMAPStore imapStore = connectToImap("imap.gmail.com",
993,
email,
oauthToken,
true);
System.out.println("Successfully authenticated to IMAP.\n");
SMTPTransport smtpTransport = connectToSmtp("smtp.gmail.com",
587,
email,
oauthToken,
true);
System.out.println("Successfully authenticated to SMTP.");
}
catch( Exception e )
{
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
throw new RuntimeException( e );
}
}
public static final class OAuth2Provider extends Provider {
private static final long serialVersionUID = 1L;
public OAuth2Provider() {
super("Google OAuth2 Provider", 1.0,
"Provides the XOAUTH2 SASL Mechanism");
put("SaslClientFactory.XOAUTH2",
"com.google.code.samples.oauth2.OAuth2SaslClientFactory");
}
}
public static void initialize() {
Security.addProvider(new OAuth2Provider());
}
public static IMAPStore connectToImap(String host, int port,
String userEmail, String oauthToken, boolean debug)
throws Exception {
Properties props = new Properties();
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);
Session session = Session.getInstance(props);
session.setDebug(debug);
session.getProperties().put("mail.imaps.sasl.enable", "true");
session.getProperties().put("mail.imaps.sasl.mechanisms", "XOAUTH2");
session.getProperties().put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);
final URLName unusedUrlName = null;
IMAPSSLStore store = new IMAPSSLStore(session, unusedUrlName);
final String emptyPassword = "";
store.connect(host, port, userEmail, emptyPassword);
return store;
}
public static SMTPTransport connectToSmtp(String host, int port,
String userEmail, String oauthToken, boolean debug)
throws Exception {
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.sasl.enable", "true");
props.put("mail.smtp.sasl.mechanisms", "XOAUTH2");
props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);
Session session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
SMTPTransport transport = new SMTPTransport(session, unusedUrlName);
// If the password is non-null, SMTP tries to do AUTH LOGIN.
final String emptyPassword = null;
transport.connect(host, port, userEmail, emptyPassword);
return transport;
}
}
The IMAP debug trace is:
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: enable SASL
DEBUG IMAPS: SASL mechanisms allowed: XOAUTH2
DEBUG IMAPS: trying to connect to host "imap.gmail.com", port 993, isSSL true
* OK Gimap ready for requests from xxx.xxx.xxx.xxx ZZZZZZZZZ
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY
A0 OK Thats all she wrote! ZZZZZZZZZ
DEBUG IMAPS: AUTH: XOAUTH
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: protocolConnect login, host=imap.gmail.com, user=som...#gmail.com, password=<non-null>
DEBUG IMAPS: SASL authentication command trace suppressed
DEBUG IMAPS: SASL Mechanisms:
DEBUG IMAPS: XOAUTH2
DEBUG IMAPS:
DEBUG IMAPS: No SASL support
DEBUG IMAPS: SASL authentication failed
DEBUG IMAPS: LOGIN command trace suppressed
DEBUG IMAPS: LOGIN command result: A1 NO Empty username or password. ZZZZZZZZZ
DEBUG IMAPS: trying to connect to host "imap.gmail.com", port 993, isSSL true
* OK Gimap ready for requests from xxx.xxx.xxx.xxx YYYYYYYYYY
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2
A0 OK Thats all she wrote! YYY
DEBUG IMAPS: AUTH: XOAUTH
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: protocolConnect login, host=imap.gmail.com, user=som...#gmail.com, password=<non-null>
DEBUG IMAPS: SASL authentication command trace suppressed
DEBUG IMAPS: SASL Mechanisms:
DEBUG IMAPS: XOAUTH2
DEBUG IMAPS:
DEBUG IMAPS: No SASL support
DEBUG IMAPS: SASL authentication failed
DEBUG IMAPS: LOGIN command trace suppressed
DEBUG IMAPS: LOGIN command result: A1 NO Empty username or password. YYYYYYYYYY
java.lang.RuntimeException: javax.mail.AuthenticationFailedException: Empty username or password. YYYYYYYYYY
This problem only occurs on a deployed node. Ensured that the provider was correct path and installed and using the latest versions of App Engine SDK that facilitates the IMAP and SMTP sockets. Triggering has been attempted via sample servlet and task on task queue.
Thank you for assistance in advance.
I've the same problem than you...
I've been researching, and I think the session isn't instantiated correctly. I attached a picture that shows the difference.
At the top of the image shows the contents of the variable "props" which is the same values for the AppEngine project (left image) that the project Normal(right image).
The down images shows the contents of the Session variable, and within this, the contents of the variables Properties. Like you can see in the left case, is null. But in the right case have values.
Here is the image: http://ricorrico.comoj.com/misc/img2.jpg
It really is a bug, is there any workaround?
Thank you very much in advance.
Regards!
Not sure if you are still running into this issue, but #user2606850 was very close to the solution. Initializing the session with the properties set does not properly initialize the session.
BUT adding the right properties AFTER the Session is created, WORKS !
Properties props = new Properties();
Session session = Session.getInstance(props);
props = session.getProperties();
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
IMAPSSLStore store = new IMAPSSLStore(session, unusedUrlName);
...
Tested an proven to work deployed to AppEngine.

why I can send email by gmail in my local, but can not send be ubuntu server?

I have using JavaMail version 1.4.3, I can sent email in my dev environment, but can not sent email when deploy in ubuntu server.
I compare the debug log as below:smtp can not be accepted but my local can.any suggestings? I also search here java mail error
local:
**DEBUG: setDebug: JavaMail version 1.4.3
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.google.com ESMTP u9sm646165paf.22 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO 10.37.129.2
250-mx.google.com at your service, [112.64.93.195]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2
250 ENHANCEDSTATUSCODES
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
ubuntu:
DEBUG: setDebug: JavaMail version 1.4.3
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.google.com ESMTP ed8sm502698qeb.7 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
WkFRITJ3c3hjZGUz
535-5.7.1 Username and Password not accepted. Learn more at
535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 ed8sm502698qeb.7 - gsmtp
15:21:33,167 ERROR ~
#6e0gki7nd
The email has not been sent
Mail error
A mail error occured : Error while sending email
play.exceptions.MailException: Error while sending email
at play.libs.Mail$2.call(Mail.java:186)
at play.libs.Mail$2.call(Mail.java:178)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at play.libs.Mail$2.call(Mail.java:183)
... 6 more
Caused by: javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted. Learn more at
535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 ed8sm502698qeb.7 - gsmtp
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:648)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
at javax.mail.Service.connect(Service.java:313)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 8 more
The most likely explanation is that you think you're using the same username and password in both cases, but you're not.
Note that the funny text after "AUTH LOGIN" is your base64 encoded username and password. Anyone can decode them. Without decoding them I can tell you that they're not the same in both cases, probably because you've altered the debug output in some way.
Check your program and make sure you're really using the same username and password in both cases.

still cannot configure Archiva mail under Tomcat

I have already looked here,
sending mail to a configured smtp server
and here,
http://www.questionhub.com/StackOverflow/2592434
and also the sendmail spec Appendix A,
but the answers just aren't helping me.
I have Archiva running under Tomcat 5.5.27 under Windows Vista, start up is fine but mail keeps crashing.
Have played with this config over a dozen times and am not getting anywhere (not sure why GT and LT signs are disappearing in my Resource tag):
Resource name="mail/Session"
auth="Container"
type="javax.mail.Session"
mail.transport.protocol="smtp"
mail.smtp.port="25"
mail.debug="true"
mail.host="mail.yyy.xxxx.edu"
mail.smtp.host="mail.yyy.xxxx.edu"
From the other threads it is UNCLEAR where to put a security.properties file. Under Tomcat does it go under \conf or does it go under \conf\Catalina\localhost?!? I have tried both - no luck!
The contents of my security.properties file is currently:
email.address.from=barretta#yyy.xxxx.edu
email.validation.subject=Archiva Maven Repository
The error message of the hour is:
Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 553 5.5.4 ... Real domain name required for sender address
(SABRE is the name of my machine.)
Once I click the button to register in the Archiva webapp, DEBUG from Tomcat stdout is:
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 "mail.yyy.xxxx.edu", port 25, isSSL false
220 dns.yyy.xxxx.edu ESMTP Sendmail 8.13.8/8.13.8; Thu, 4 Nov 2010 20:57:03 -0700
DEBUG SMTP: connected to host "mail.yyy.xxxx.edu", port: 25
EHLO sabre
250-dns.yyy.xxxx.edu Hello [zzz.zzz.zz.zz], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-DELIVERBY
250 HELP
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "DIGEST-MD5 CRAM-MD5 LOGIN PLAIN"
DEBUG SMTP: Found extension "DELIVERBY", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:
553 5.5.4 ... Real domain name required for sender address
com.sun.mail.smtp.SMTPSendFailedException: 553 5.5.4 ... Real domain name required for sender address
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
then a stack exception...
I can take the same mailapi jar I have under tomcat\common\lib and execute a simple Java standalone mail client that takes nothing more than FROM, TO, and SERVER and successfully sends email. SERVER value is same as mail host above, mail.yyy.xxxx.edu. No password/authentication. So I don't think it is my machine sabre, it is my Archiva configuration.
Please help.
I managed to solve the problem. The security.properties files lies buried deep within the archiva deployment under Tomcat, at:
\webapps\archiva\WEB-INF\classes\org\apache\maven\archiva. It is NOT under \conf!!!!
I added the property email.from.address as described in other postings.
Also whittled down the Resource element in \conf\Catalina\localhost\archiva.xml to:
<Resource name="mail/Session"
auth="Container"
type="javax.mail.Session"
mail.debug="true"
mail.host="mail.mii.ucla.edu"
mail.smtp.host="mail.mii.ucla.edu" />
I have other problems now, which I will post about separately.

Resources