javax.mail Sending email fails due to HELO/EHLO argument "localhost," invalid - server

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.

Related

Jenkins Email SMTP server errors

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

How to get Sendmail to listen on 110 POP3

I'm trying to configure Sendmail to listen on on 110 POP3 on a ec2 server. I need it for a newsletter app so that it can check for bounces. When I try to telnet in on port 110 I get a connection error.
root:/# telnet sub.domain.com 110
Trying 5?.??.?.?0...
telnet: Unable to connect to remote host: Connection refused
root:/# telnet sub.domain.com 25
Trying 5?.??.?.?0...
Connected to sub.domain.com.
Escape character is '^]'.
220 ip-172-31-54-114.ec2.internal ESMTP Sendmail 8.14.4/8.14.4/Debian-4.1ubuntu1; Wed, 30 Nov 2016 10:24:50 GMT; (No UCE/UBE) logging access from: [5?.??.?.?0](FORGED)-ec2-5?-??-?-?0.compute-1.amazonaws.com [5?.??.?.?0] (may be forged)
^]
telnet> quit
Connection closed.
When I lsof on port 25 I can see that it's working but not on 110.
root:/# lsof -n -i :25
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sendmail- 4279 root 4u IPv4 2349285 0t0 TCP *:smtp (LISTEN)
root:/# lsof -n -i :110
root:/#
Do I need to edit the sendmail.mc file, previously I commented out the below lines so that smtp would listen to all IPs.
dnl DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl
dnl DAEMON_OPTIONS(`Family=inet, Name=MSP-v4, Port=submission, M=Ea, Addr=127.0.0.1')dnl
I've searched the sendmail.cf & sendmail.mc for any references to pop3/port110 configuration but can't see anything.
Sendmail MTA acts like SMTP server. You need separate program/server to service POP3 protocol e.g. dovecot IMAP/POP server.
Sendmail-FAQ-4.19 : How do I configure sendmail for POP/IMAP/...?

SSH Tunnelling - Remote Debugging

I can ssh into the server say abc.xyz on port 22 but i can't remote debug it in Eclipse. Here is the additional info :
Server startup arguments -
-Xdebug -Xrunjdwp:transport=dt_socket,address=1234,server=y,suspend=n
Confirmation from logs -
Listening for transport dt_socket at address: 1234
When I telnet on my local system -
local-machine% telnet abc-xyz 1234
Trying xx.xx.xx.xx...
telnet: connect to address xx.xx.xx.xx: Connection timed out
telnet: Unable to connect to remote host: Connection timed out
When I telnet on the server(abc.xyz) -
abc-xyz% telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Connection closed by foreign host.
I've tried setting up tunnel via -
ssh -L 1234:localhost:1234 user#abc-xyz
ssh -L 1234:127.0.0.1:1234 user#abc-xyz
I'm attaching debugger in Eclipse with this config -
Connection type - Standard (Socket attach)
Host - localhost
Port - 1234
Can't get Eclipse to attach to 1234.
After setting up SSH Tunnel, if i manually try to connect to the port, i get this response -
local-machine% telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Connection closed by foreign host.
and I see an entry in catalina.out as:
channel 4: open failed: connect failed: Connection refused
Any help would be appreciated.
EDIT - 1:
I ran
abc-xyz% ~#
and got the following output:
The following connections are open:
#2 client-session (t4 r0 i0/0 o0/0 fd 7/8 cc -1)
#3 direct-tcpip: listening port 1234 for localhost port 1234, connect from 127.0.0.1 port 23456 (t4 r1 i0/0 o0/0 fd 10/10 cc -1)
I think ssh tunneling is working, it's just the way i'm connecting with Eclipse which is going wrong here.
I just had to increase timeout. (Can be done via Window->Preferences->Java->Debugging. Set it to some appropriate value.)

How to send email with javamail through gmail-account from inside openshift server?

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);
}
}

Why am I getting a nulljavax.mail.AuthenticationFailedException?

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).