Could someone help me to clarify the following matter? Thanks
LocalDate localDate = LocalDate.now().minusDays(600);
SearchTerm newer = new SentDateTerm(ComparisonTerm.GE,
Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
Message[] messages = inbox.search(newer);
The messages returned only 1000 messages, actually, I have > 1000 messages in the mailbox. Do we have a limitation on this?
Debug log:
DEBUG: setDebug: JavaMail version 1.5.6
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: closeFoldersOnStoreFailure
DEBUG IMAP: trying to connect to host "imap.secureserver.net", port 143, isSSL false
* OK [CAPABILITY IMAP4rev1 UNSELECT STARTTLS ID CHILDREN NAMESPACE IDLE UIDPLUS] Courier-IMAP ready. Copyright 1998-2004 Double Precision, Inc. See COPYING for distribution information.
DEBUG IMAP: protocolConnect login, host=imap.secureserver.net, user=xxx(edited), password=
DEBUG IMAP: mechanism PLAIN not supported by server
DEBUG IMAP: mechanism LOGIN not supported by server
DEBUG IMAP: mechanism NTLM not supported by server
DEBUG IMAP: mechanism XOAUTH2 disabled by property: mail.imap.auth.xoauth2.disable
DEBUG IMAP: LOGIN command trace suppressed
DEBUG IMAP: LOGIN command result: A0 OK LOGIN Full IMAP support is enabled
A1 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT STARTTLS ID CHILDREN NAMESPACE IDLE UIDPLUS
A1 OK CAPABILITY completed
DEBUG IMAP: connection available -- size: 1
A2 EXAMINE INBOX
* FLAGS (\Draft \Answered \Flagged \Deleted \Seen)
* OK [PERMANENTFLAGS (\Draft \Answered \Flagged \Deleted \Seen)] Limited
* 92611 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1] Ok
* OK [UIDNEXT 116157] Predicted next UID
A2 OK [READ-ONLY] EXAMINE completed.
A3 SEARCH SENTSINCE 19-Aug-2016 ALL
* SEARCH 91612 91613 91614 91615 91616 91617 91618 91619 91620 91621 ...
A3 OK SEARCH done.
DEBUG IMAP: IMAPStore cleanup, force false
DEBUG IMAP: close folder
A4 CLOSE
A4 OK mailbox closed.
DEBUG IMAP: added an Authenticated connection -- size: 1
A5 LOGOUT
* BYE IMAP server shutting down
A5 OK LOGOUT completed
DEBUG IMAP: IMAPStore cleanup done
DEBUG IMAP: IMAPStore cleanup, not connected
Code using to connect:
Properties properties = System.getProperties();
properties.setProperty("mail.store.protocol", "imaps");
properties.setProperty("mail.imap.starttls.enable", "true");
String host = "imap.mail.me.com";
int port = 993;
String result = null;
TestLogger.log("Connecting to Imap..");
try {
//Connect to the server
Session session = Session.getInstance(properties);
session.setDebug(true);
Store store = session.getStore();
store.connect(host, port, "username","pass");
The store.connect throws A0 BAD Parse Error, full debug output:
Attempt #0
Connecting to Imap..
DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
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: trying to connect to host "imap.mail.me.com", port 993, isSSL true
* OK
DEBUG IMAPS: AUTH: ATOKEN
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: protocolConnect login, host=imap.mail.me.com, user=<user>, password=<non-null>
DEBUG IMAPS: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAPS: AUTHENTICATE PLAIN command result: A0 BAD Parse Error
***** ERROR *****: Error
***** ERROR *****: javax.mail.MessagingException: A0 BAD Parse Error;
nested exception is:
com.sun.mail.iap.BadCommandException: A0 BAD Parse Error
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:668)
at javax.mail.Service.connect(Service.java:295)
at
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.
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.
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.