I am making a web app that sends emails automatically, so I am using javamail. I need to use the SMPT of my company, and no matter what I do I get a nulljavax.mail.AuthenticationFailedException. This is the first time I have used it and I'm really frustrated since I have tried a wide number of solutions and still I can't figure out what's wrong. I made a test using gmail and it worked, but so far nothing has helped. here's my code:
UPDATE: I have made changes to my code, and got rid of the authenticator as suggested.
final String username = "dva.clamadrid#grupoautofin.com";
final String password = "Leprechaun01";
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props);
try {
session.setDebug(true);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("dva.clamadrid#grupoautofin.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("dva.clamadrid#grupoautofin.com"));
message.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(Copy));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport transport = session.getTransport("smtp");
transport.connect("SMTP.grupoautofin.com", 25, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
Log.i("Estás enviando: ",""+message.toString());
System.out.println("Done");
}catch(AuthenticationFailedException e) {
Log.e("ERROR DE AUTENTIFICACION: ",""+e.getMessage()+e);
e.printStackTrace();
bandera = false;
} catch (MessagingException e) {
bandera=false;
Log.e("ERROR ENVIANDO: ",""+e.getMessage()+e);
e.printStackTrace();
//throw new RuntimeException(e);
}
Also, my Error Log, now with Debug Messages:
10-13 15:56:13.504: I/System.out(802): DEBUG: setDebug: JavaMail version 1.4.1
10-13 15:56:13.544: I/System.out(802): DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1]
10-13 15:56:13.544: I/System.out(802): DEBUG SMTP: useEhlo true, useAuth true
10-13 15:56:13.544: I/System.out(802): DEBUG SMTP: trying to connect to host "SMTP.grupoautofin.com", port 25, isSSL false
10-13 15:56:13.835: I/System.out(802): 220 mtysmtp01.mexico.hosting.triara SMTP Server 01 is ready. Mon, 13 Oct 2014 14:56:13 -0500
10-13 15:56:13.845: I/System.out(802): DEBUG SMTP: connected to host "SMTP.grupoautofin.com", port: 25
10-13 15:56:13.855: I/System.out(802): EHLO localhost
10-13 15:56:13.905: I/System.out(802): 250-mtysmtp01.mexico.hosting.triara Hello [189.203.255.42]
10-13 15:56:13.905: I/System.out(802): 250-TURN
10-13 15:56:13.905: I/System.out(802): 250-SIZE 27262976
10-13 15:56:13.915: I/System.out(802): 250-ETRN
10-13 15:56:13.915: I/System.out(802): 250-PIPELINING
10-13 15:56:13.915: I/System.out(802): 250-DSN
10-13 15:56:13.915: I/System.out(802): 250-ENHANCEDSTATUSCODES
10-13 15:56:13.915: I/System.out(802): 250-8bitmime
10-13 15:56:13.915: I/System.out(802): 250-BINARYMIME
10-13 15:56:13.915: I/System.out(802): 250-CHUNKING
10-13 15:56:13.915: I/System.out(802): 250-VRFY
10-13 15:56:13.915: I/System.out(802): 250-X-EXPS GSSAPI NTLM LOGIN
10-13 15:56:13.915: I/System.out(802): 250-X-EXPS=LOGIN
10-13 15:56:13.925: I/System.out(802): 250-AUTH GSSAPI NTLM LOGIN
10-13 15:56:13.925: I/System.out(802): 250-AUTH=LOGIN
10-13 15:56:13.925: I/System.out(802): 250-X-LINK2STATE
10-13 15:56:13.925: I/System.out(802): 250-XEXCH50
10-13 15:56:13.925: I/System.out(802): 250 OK
10-13 15:56:13.935: I/System.out(802): DEBUG SMTP: Found extension "TURN", arg ""
10-13 15:56:13.935: I/System.out(802): DEBUG SMTP: Found extension "SIZE", arg "27262976"
10-13 15:56:13.945: I/System.out(802): DEBUG SMTP: Found extension "ETRN", arg ""
10-13 15:56:13.945: I/System.out(802): DEBUG SMTP: Found extension "PIPELINING", arg ""
10-13 15:56:13.945: I/System.out(802): DEBUG SMTP: Found extension "DSN", arg ""
10-13 15:56:13.945: I/System.out(802): DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
10-13 15:56:13.955: I/System.out(802): DEBUG SMTP: Found extension "8bitmime", arg ""
10-13 15:56:13.955: I/System.out(802): DEBUG SMTP: Found extension "BINARYMIME", arg ""
10-13 15:56:13.955: I/System.out(802): DEBUG SMTP: Found extension "CHUNKING", arg ""
10-13 15:56:13.965: I/System.out(802): DEBUG SMTP: Found extension "VRFY", arg ""
10-13 15:56:13.965: I/System.out(802): DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM LOGIN"
10-13 15:56:13.965: I/System.out(802): DEBUG SMTP: Found extension "X-EXPS=LOGIN", arg ""
10-13 15:56:13.975: I/System.out(802): DEBUG SMTP: Found extension "AUTH", arg "GSSAPI NTLM LOGIN"
10-13 15:56:13.975: I/System.out(802): DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
10-13 15:56:13.985: I/System.out(802): DEBUG SMTP: Found extension "X-LINK2STATE", arg ""
10-13 15:56:14.004: I/System.out(802): DEBUG SMTP: Found extension "XEXCH50", arg ""
10-13 15:56:14.004: I/System.out(802): DEBUG SMTP: Found extension "OK", arg ""
10-13 15:56:14.015: I/System.out(802): DEBUG SMTP: Attempt to authenticate
10-13 15:56:14.025: I/System.out(802): AUTH LOGIN
10-13 15:56:14.075: I/System.out(802): 334 VXNlcm5hbWU6
10-13 15:56:14.085: I/System.out(802): ZHZhLmNsYW1hZHJpZEBncnVwb2F1dG9maW4uY29t
10-13 15:56:14.135: I/System.out(802): 334 UGFzc3dvcmQ6
10-13 15:56:14.135: I/System.out(802): TGVwcmVjaGF1bjAx
10-13 15:56:14.416: I/System.out(802): 535 5.7.3 Authentication unsuccessful.
10-13 15:56:14.424: E/ERROR DE AUTENTIFICACION:(802): nulljavax.mail.AuthenticationFailedException
Still getting the same error, what else am I doing wrong? Thanks in advance.
First, you don't need the Authenticator, get rid of it.
Second, you don't need the host, port, or auth properties if you're going to call the connect method explicitly so you can get rid of them too.
You've done something to verify that you're passing the correct username and password, right?
Turn on session debugging and the debug output might provide more clues as to what's going wrong. You might need to set the "mail.debug.auth" property to "true" to see the full authentication protocol exchange (which will include your password) to see the details of what's failing. If you still can't figure it out, post the debug output (without the authentication exchange).
Related
So having some issues in Jenkins while setting up E-Mail notification.
Using these settings which work fine in code on my websites and azure pipelines
smtp: tulip.specialservers.com
port: 25
EnableSsl: false
user: xxxxxx#xxxxx.com
password: xxxxxxx
As I say these cred's work elsewhere, howverever on Jenkins I have tried
smtp: tulip.specialservers.com
port: 25
EnableSsl: false
user: xxxxxx#xxxxx.com
password: xxxxxxx
jakarta.mail.AuthenticationFailedException: 535 Invalid Username or Password ??
smtp: tulip.specialservers.com
port: 465
EnableSsl: false
user: xxxxxx#xxxxx.com
password: xxxxxxx
jakarta.mail.MessagingException: Got bad greeting from SMTP host: tulip.specialservers.com, port: 465, response: [EOF] ???
smtp: tulip.specialservers.com
port: 25
EnableSsl: true
user: xxxxxx#xxxxx.com
password: xxxxxxx
javax.net.ssl.SSLException: Unsupported or unrecognized SSL message ???
smtp: tulip.specialservers.com
port: 465
EnableSsl: true
user: xxxxxx#xxxxx.com
password: xxxxxxx
jakarta.mail.AuthenticationFailedException: 535 Invalid Username or Password ??
Also when running a job I see this in the console output
DEBUG: getProvider() returning jakarta.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=tulip.specialservers.com, user=jenkins, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "tulip.specialservers.com", port 25, isSSL false
220 tulip.specialservers.com ESMTP MailEnable Service, Version: 10.43-- ready at 01/18/23 17:21:32
DEBUG SMTP: connected to host "tulip.specialservers.com", port: 25
EHLO DESKTOP-8DTOB41
250-tulip.specialservers.com [86.26.142.130], this server offers 5 extensions
250-AUTH LOGIN
250-SIZE 40960000
250-HELP
250-AUTH=LOGIN
250 STARTTLS
DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "SIZE", arg "40960000"
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: protocolConnect login, host=tulip.specialservers.com, user=***#*******.com, 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 failed
AuthenticationFailedException message: 535 Invalid Username or Password
This seems to say no password was found even though it is setup in manage jenkins > credentials
When I last set this up a couple of years ago there was no issue, can anyone provide me with some ideas please.
Ta
I am using javax.mail to send emails from my backend to my personal email address (I wanna get a notification in case something particular happens).
On my local machine (that is in debug/development mode) this works fine. But on my production server I am encountering the following problem:
DEBUG: JavaMail version 1.5.5
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: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 smtp.gmail.com ESMTP q2sm11403478qtf.52 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587
EHLO localhost,
501-5.5.4 HELO/EHLO argument "localhost," invalid, closing connection.
501 5.5.4 https://support.google.com/mail/?p=helo q2sm11403478qtf.52 - gsmtp
HELO localhost,
DEBUG SMTP: EOF: [EOF]
javax.mail.MessagingException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:2215)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:1599)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:705)
at javax.mail.Service.connect(Service.java:388)
at javax.mail.Service.connect(Service.java:246)
at javax.mail.Service.connect(Service.java:195)
Obviously HELO/EHLO argument "localhost," invalid is the problem. I first thought I had to change me /etc/hosts entries. But actually they should be okay, they are like this:
$ cat /etc/hosts
127.0.0.1 localhost, myremotemachine
87.85.108.234 myremotemachine
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
So, I mapped my servername to the 127.0.0.1 and on my public ip address. Also, in the console the command hostname outputs myremotemachine.
So, what else do I have to do here?
First, there should be no commas between names in the /etc/hosts file.
You can move the 87.85.108.234 entry above the localhost entry, or remove myremotemachine from the localhost entry, or set the JavaMail mail.smtp.localhost property to the name you want to use.
Recently, I've been experiencing problems with my email setup using Emacs (24.4.2) + Gnus (0.12). It seems that the TSL connection is not working:
gnutls.c: [0] (Emacs) fatal error: The TLS connection was non-properly terminated.
gnutls.el: (err=[-110] The TLS connection was non-properly terminated.) boot: (:priority NORMAL :hostname smtp.me.com :loglevel 0 :min-prime-bits 256 :trustfiles nil :crlfiles nil :keylist nil :verify-flags nil :verify-error nil :callbacks nil)
smtpmail-send-it: Sending failed: 530 5.7.0 No STARTTLS command has been given.
Is it a Gnus or Openssl problem? How should I debug and fix it?
Here is the output of the smtp trace buffer:
220 nk11p00mm-asmtp003.example.com -- Server ESMTP (Oracle Communications Messaging Server 7u4-27.10(7.0.4.27.9) 64bit (built Jun 6 2014))
250-nk11p00mm-asmtp003.example.com
250-8BITMIME
250-PIPELINING
250-CHUNKING
250-DSN
250-ENHANCEDSTATUSCODES
250-EXPN
250-HELP
250-XADR
250-XSTA
250-XCIR
250-XGEN
250-XLOOP 098E7F59418D8F04E0C7135651497A4E
250-STARTTLS
250-NO-SOLICITING
250 SIZE 28311552
220 2.5.0 Go ahead with TLS negotiation.
Process smtpmail deleted
220 nk11p00mm-asmtp003.example.com -- Server ESMTP (Oracle Communications Messaging Server 7u4-27.10(7.0.4.27.9) 64bit (built Jun 6 2014))
MAIL FROM:<john.doe#example.com>
250-nk11p00mm-asmtp003.example.com
250-8BITMIME
250-PIPELINING
250-CHUNKING
250-DSN
250-ENHANCEDSTATUSCODES
250-EXPN
250-HELP
250-XADR
250-XSTA
250-XCIR
250-XGEN
250-XLOOP 098E7F59418D8F04E0C7135651497A4E
250-STARTTLS
250-NO-SOLICITING
250 SIZE 28311552
RCPT TO:<john.doe#example.com>
530 5.7.0 No STARTTLS command has been given.
QUIT
503 5.5.0 No MAIL FROM command has been issued.
I have a webapplication running at Openshift Free (redhat webhotel).
From this app I would like to send an email through my gmail account with the javax.mail-api.
When I try to run my code-attempts from my developer machine it works fine both with SSL and without SSL.
But when I run this from a JSP-page in my openshift server it does not work. I get this response back from gmail:
534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbs0N
534-5.7.14 -wfEXm3iqKdenfgsums1_oLzBr3toWk44lKCVSpdKHkI2cJpo5ytmXFAU2LVn_4a3wrT-2
534-5.7.14 YUjbzlo4QJZRTxuWxujUOMJW8m5HMbUgHqZp0cBWjGZH-Nr5CZrHql_uZx_6IaEot3NJ-m
534-5.7.14 pBj85PCczPqx2q7NFQ6faPMgDRp7yEXlDAKOEZZ10gjxhQ3NLGFYV-_n9yS2ae49ZQOFHn
534-5.7.14 VTLSwBg> Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 g4sm1374527qas.22 - gsmtp
Below is code without SSL:
public static void sendGmail(String to, String subject, String text) throws AddressException, MessagingException
{
final String SMTP_HOST = "smtp.gmail.com";
final String SMTP_PORT = "587";
final String GMAIL_USERNAME = "xxx#gmail.com";
final String GMAIL_PASSWORD = "xxx";
System.out.println("Process Started");
Properties prop = System.getProperties();
prop.setProperty("mail.smtp.starttls.enable", "true");
prop.setProperty("mail.smtp.host", SMTP_HOST);
prop.setProperty("mail.smtp.user", GMAIL_USERNAME);
prop.setProperty("mail.smtp.password", GMAIL_PASSWORD);
prop.setProperty("mail.smtp.port", SMTP_PORT);
prop.setProperty("mail.smtp.auth", "true");
Session session = Session.getInstance(prop, new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(GMAIL_USERNAME,
GMAIL_PASSWORD);
}
});
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(GMAIL_USERNAME));
message.addRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
message.setSubject(subject);
message.setText(text);
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
Transport transport = session.getTransport("smtp");
transport.connect(SMTP_HOST, GMAIL_USERNAME, GMAIL_PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
}
Below is code with SSL:
public static void sendGmail(String to, String subject, String text) throws AddressException, MessagingException
{
String host = "smtp.gmail.com";
final String GMAIL_USERNAME = "xxx#gmail.com";
final String GMAIL_PASSWORD = "xxx";
Properties props = new Properties();
props.put("mail.smtps.host", host);
props.put("mail.smtps.auth", "true");
Session session = Session.getInstance(props, null);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setSubject(subject);
msg.setText(text);
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setFrom(new InternetAddress(username));
msg.setHeader("X-Mailer", "smtpsend");
msg.setSentDate(new Date());
SMTPTransport t = (SMTPTransport)session.getTransport("smtps");
try
{
t.connect(host, username, password);
t.sendMessage(msg, msg.getAllRecipients());
}
finally
{
t.close();
}
}
As you can see I run my attempts in debug mode for the session so below is the output from my attempts:
The debug output from my developer machine with SSL
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
220 mx.google.com ESMTP ny6sm229296lbb.2 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO fredand
250-mx.google.com at your service, [90.230.21.163]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER
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 XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER"
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: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
bm9ycnVkZGVuLnZhZ2ZvcmVuaW5nQGdtYWlsLmNvbQ==
334 UGFzc3dvcmQ6
bm9ycnVkZGVuOTc=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<xxx#gmail.com>
250 2.1.0 OK ny6sm229296lbb.2 - gsmtp
RCPT TO:<xxx#hotmail.com>
250 2.1.5 OK ny6sm229296lbb.2 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: xxx#hotmail.com
DATA
354 Go ahead ny6sm229296lbb.2 - gsmtp
Date: Tue, 4 Nov 2014 15:23:48 +0100 (CET)
From: xxx#gmail.com
To: xxx#hotmail.com
Message-ID: <30266940.0.1415111029890.JavaMail.RPS#fredand>
Subject: Subject_Tue Nov 04 15:23:48 CET 2014
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: smtpsend
text_Tue Nov 04 15:23:48 CET 2014
.
250 2.0.0 OK 1415111029 ny6sm229296lbb.2 - gsmtp
QUIT
221 2.0.0 closing connection ny6sm229296lbb.2 - gsmtp
The debug output from my openshift server with SSL
DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
220 mx.google.com ESMTP 4sm1230842qax.48 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO ex-std-node449.prod.rhcloud.com
250-mx.google.com at your service, [54.90.46.53]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER
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 XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER"
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: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
AUTH LOGIN
334 VXNlcm5hbWU6
bm9ycnVkZGVuLnZhZ2ZvcmVuaW5nQGdtYWlsLmNvbQ==
334 UGFzc3dvcmQ6
bm9ycnVkZGVuOTc=
534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbsvV
534-5.7.14 5K74amuA1WqDS9CFS1UPmuS3XUVU7lq0Agwb5DPcG69Z5fkYe6RUZrzAKPDWy9tQzq2BDg
534-5.7.14 1AxC2MmT1D1UXOXLG8cZuf7yKxKEUtaLo79a-fROXRiwCvMaqdvYXhqiIslXDTWJQZVe5W
534-5.7.14 qYvj9_ov5cziZe3ao5usZ-o58tHCv48yzrRm5SppAESXnvmv35ZLy4U9qF14GLEXHT7Wzj
534-5.7.14 QuIfn6w> Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 4sm1230842qax.48 - gsmtp
The debug output from my developer machine without SSL
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 mx.google.com ESMTP x6sm542099lbj.40 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587
EHLO fredand
250-mx.google.com at your service, [90.230.21.163]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
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 "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO fredand
250-mx.google.com at your service, [90.230.21.163]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER
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 XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER"
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: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
bm9ycnVkZGVuLnZhZ2ZvcmVuaW5nQGdtYWlsLmNvbQ==
334 UGFzc3dvcmQ6
bm9ycnVkZGVuOTc=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<xxx#gmail.com>
250 2.1.0 OK x6sm542099lbj.40 - gsmtp
RCPT TO:<xxx#hotmail.com>
250 2.1.5 OK x6sm542099lbj.40 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: xxx#hotmail.com
DATA
354 Go ahead x6sm542099lbj.40 - gsmtp
From: xxx#gmail.com
To: xxx#hotmail.com
Message-ID: <27966883.0.1415135485593.JavaMail.RPS#fredand>
Subject: Subject_Tue Nov 04 22:11:24 CET 2014
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
text_Tue Nov 04 22:11:24 CET 2014
.
250 2.0.0 OK 1415135486 x6sm542099lbj.40 - gsmtp
The debug output from my openshift server without SSL
DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.4]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 mx.google.com ESMTP g4sm1374527qas.22 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587
EHLO ex-std-node449.prod.rhcloud.com
250-mx.google.com at your service, [54.90.46.53]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
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 "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO ex-std-node449.prod.rhcloud.com
250-mx.google.com at your service, [54.90.46.53]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER
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 XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER"
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: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
AUTH LOGIN
334 VXNlcm5hbWU6
bm9ycnVkZGVuLnZhZ2ZvcmVuaW5nQGdtYWlsLmNvbQ==
334 UGFzc3dvcmQ6
bm9ycnVkZGVuOTc=
534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbs0N
534-5.7.14 -wfEXm3iqKdenfgsums1_oLzBr3toWk44lKCVSpdKHkI2cJpo5ytmXFAU2LVn_4a3wrT-2
534-5.7.14 YUjbzlo4QJZRTxuWxujUOMJW8m5HMbUgHqZp0cBWjGZH-Nr5CZrHql_uZx_6IaEot3NJ-m
534-5.7.14 pBj85PCczPqx2q7NFQ6faPMgDRp7yEXlDAKOEZZ10gjxhQ3NLGFYV-_n9yS2ae49ZQOFHn
534-5.7.14 VTLSwBg> Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 g4sm1374527qas.22 - gsmtp
Do you guys get any clue why this is not working from my openshift server?
Best regards
Fredrik
Thanks for all help.
It seems like I needed to activate the IMAP at my gmail account.
After that it worked fine.
Best regards
Fredrik
I had some difficulties with gmail, so I shifted to SendGrid to integrate JavaMail into a web application deployed onto OPENSHIFT for a dummy project.
I used SendGrid Trial.
Some Changes --
// The SendGrid SMTP server.
String SMTP_HOST_NAME = "smtp.sendgrid.net";
Properties properties = new Properties();
// Specify SMTP values.
properties.put("mail.transport.protocol", "smtp");
properties.put("mail.smtp.host", SMTP_HOST_NAME);
properties.put("mail.smtp.port", 587);
properties.put("mail.smtp.auth", "true");
You have to these two --
final String sendGridUser ="NameUChoose"; // Use At SendGrid Registration
final String sendGridPassword="*****" ; // Use At SendGrid Registration
The rest is pretty much the same as other JavaMail code.
You have to authenticate your credentials also, so --
// Create the authenticator object.
Authenticator authenticator = new SMTPAuthenticator();
Create a separate java class , like --
package com.rana;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class SMTPAuthenticator extends Authenticator
{
final String sendGridUser ="NameUChoose";
final String sendGridPassword="*******;
public PasswordAuthentication getPasswordAuthentication()
{
String username = sendGridUser;
String password = sendGridPassword;
return new PasswordAuthentication(username, password);
}
}
I have the following problem. I have a Seam web application which features e-mail composition and sending using Javamail. The application sends mail just fine in my local JBoss application server, but it doesn't work on the JBoss server installed in my myhosting.com VPS. I read that the issue may be because the web server or the URL to which I'm trying to connect does not have a valid certificate from an authorized CA, but I run an utility (http://cold-caffein.blogspot.com/2011/07/looks-like-article-no-more-unable-to.html) that lets me verify the certificates and they appear to be fine (I'm connecting to Gmail).
The relevant code for setting Session properties follows:
props.put("mail.smtp.auth", "true");
props.setProperty("mail.smtp.starttls.enable", "true");
I read that another cause for the issue could be using mail.smtp.starttls.enable set to true, but the code doesn't work at all (in my local server or in the VPS) if I omit the second line or set the property to false.
I don't know if the problem has something to do with the mail2web mail service that myhosting offers (look at line 9 in both logs I'm providing below, it's where things start going different). Here are the local Javamail log and the VPS' server log (the latter shows the error I'm getting):
Local log:
18:57:31,129 INFO [STDOUT] DEBUG: setDebug: JavaMail version 1.4ea
18:57:31,227 INFO [STDOUT] DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
18:57:31,383 INFO [STDOUT] DEBUG SMTP: useEhlo true, useAuth true
18:57:31,384 INFO [STDOUT] DEBUG SMTP: useEhlo true, useAuth true
18:57:31,384 INFO [STDOUT] DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
18:57:31,677 INFO [STDOUT] 220 mx.google.com ESMTP c8sm4881699yhm.14
18:57:31,677 INFO [STDOUT] DEBUG SMTP: connected to host "smtp.gmail.com", port: 25
18:57:31,680 INFO [STDOUT] EHLO SOFMANSERVER
18:57:32,088 INFO [STDOUT] 250-mx.google.com at your service, [200.25.201.121]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250 PIPELINING
18:57:32,088 INFO [STDOUT] DEBUG SMTP: Found extension "SIZE", arg "35882577"
18:57:32,088 INFO [STDOUT] DEBUG SMTP: Found extension "8BITMIME", arg ""
18:57:32,088 INFO [STDOUT] DEBUG SMTP: Found extension "STARTTLS", arg ""
18:57:32,088 INFO [STDOUT] DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
18:57:32,088 INFO [STDOUT] DEBUG SMTP: Found extension "PIPELINING", arg ""
18:57:32,088 INFO [STDOUT] STARTTLS
18:57:32,212 INFO [STDOUT] 220 2.0.0 Ready to start TLS
18:57:32,803 INFO [STDOUT] EHLO SOFMANSERVER
18:57:33,829 INFO [STDOUT] 250-mx.google.com at your service, [200.25.201.121]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH
250-ENHANCEDSTATUSCODES
250 PIPELINING
18:57:33,829 INFO [STDOUT] DEBUG SMTP: Found extension "SIZE", arg "35882577"
18:57:33,829 INFO [STDOUT] DEBUG SMTP: Found extension "8BITMIME", arg ""
18:57:33,829 INFO [STDOUT] DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH"
18:57:33,829 INFO [STDOUT] DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
18:57:33,829 INFO [STDOUT] DEBUG SMTP: Found extension "PIPELINING", arg ""
18:57:33,829 INFO [STDOUT] DEBUG SMTP: Attempt to authenticate
18:57:33,829 INFO [STDOUT] AUTH LOGIN
...
and mail is sent sucessfully.
VPS log:
2011-10-26 19:54:10,290 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG: setDebug: JavaMail version 1.4ea
2011-10-26 19:54:10,292 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
2011-10-26 19:54:10,335 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG SMTP: useEhlo true, useAuth true
2011-10-26 19:54:10,335 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG SMTP: useEhlo true, useAuth true
2011-10-26 19:54:10,335 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
2011-10-26 19:54:10,418 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) 220 xsmtp05.mail2web.com ESMTP Exim Wed, 26 Oct 2011 19:54:09 -0400
2011-10-26 19:54:10,418 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG SMTP: connected to host "smtp.gmail.com", port: 25
2011-10-26 19:54:10,418 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) EHLO <my-vps-host-name>
2011-10-26 19:54:10,456 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) 250-xsmtp05.mail2web.com Hello <my-vps-host-name> [<my-vps-ip>]
250-SIZE 104857600
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2011-10-26 19:54:10,456 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG SMTP: Found extension "SIZE", arg "104857600"
2011-10-26 19:54:10,456 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG SMTP: Found extension "PIPELINING", arg ""
2011-10-26 19:54:10,456 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
2011-10-26 19:54:10,456 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG SMTP: Found extension "STARTTLS", arg ""
2011-10-26 19:54:10,456 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) DEBUG SMTP: Found extension "HELP", arg ""
2011-10-26 19:54:10,456 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) STARTTLS
2011-10-26 19:54:10,582 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) 220 TLS go ahead
2011-10-26 19:54:10,582 INFO [STDOUT] (http-<my-vps-ip-and-jboss-port>-15) EHLO <my-vps-host-name>
2011-10-26 19:54:10,623 ERROR [<Class that sends mail>] (http-<my-vps-ip-and-jboss-port>-15) Can't send command to SMTP host
javax.mail.MessagingException: Can't send command to SMTP host;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
...
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
...
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
...
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
What should I do to get rid of this error?
Problem was solved, it was neither a network problem or code problem. We were using javamail-1.4 and after upgrading to version 1.4.4, the issue was gone.
You can upgrade library javax.mail.jar at https://java.net/projects/javamail/pages/Home (now version is 1.5.5) and add code :
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
props.put("mail.smtp.ssl.trust", "*");
props.put("mail.smtp.ssl.socketFactory", sf);