sending email using Java mail Api with app deployed in tomcat - java

I am trying to send email using java Mail Api + Spring-boot Application.
The properties which are being used are :
mail:
host: smtp.gmail.com
port: 587
username: niranjan.numeroeins#gmail.com
password: msiyyyyyvzcbox # App password for less secure web app procured
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.gmail.com
The above config works with my spring-boot+JavaMail Api nicely when i run jar directly using "java -jar myJar.jar". But once the application is deployed inside tomcat container it starts giving error as it would if you are trying to access Gmail server with less secure app like our web app code . Looks like some config issue on tomcat side(using tomcat-9)? Please help . Here is the log trace :
org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is jav
ax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials j22sm1775206pjz.3 - gsmtp
Please note that you will get same error if you try sending the email with actual password and not App password https://support.google.com/accounts/answer/185833?hl=en

Related

Gmail account authentication error while sending mail in android application

I am getting following error when i am trying to send message from android application with gmailapi.
"Could not connect to SMTP host: relay.jangosmtp.net, port: 465, response: -1"
Since 2015 google is not allowing "less secure apps" to connect through their SMTP port (this means you need a ssl or tls certificate).
To allow them you could try this: https://support.google.com/accounts/answer/6010255?hl=en

javax.mail.MessagingException: * BYE Internal error occurred

I am trying to install JavaMail on a CentOS 7 development machine using localhost only for the emails. Towards this end, I have installed dovecot, postfix, and mailx. I just installed dovecot using the instructions in this tutorial. But my JavaMail test code has been giving me all sorts of authentication errors when I try to read an inbox. How can I resolve these authentication errors so that I can log in?
At first, I was getting errors related to not finding a certificate, but I was able to resolve all those errors by commenting out any mention of ssl in the config files, by changing the protocol to imap instead of imaps, and by changing authentication to plain instead of login. (I can do all these things because it is a development machine and I just want to get JavaMail working before adding security in afterwards.) But after all those changes, I am still getting:
javax.mail.MessagingException: * BYE Internal error occurred.
Refer to server log for more information.
The line of code that throws the error is:
store.connect("localhost.localdomain", "root", "somepassword");
Note that typing hostname in the CentOS terminal results in localhost.localdomain.
The /var/log/maillog records are:
Jan 8 16:08:01 localhost dovecot: imap-login: Login: user=<root>, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1, mpid=7965, secured, session=<yb8l8ywMdwB/AAAB>
Jan 8 16:08:01 localhost dovecot: imap: Error: user root: Invalid settings in userdb: userdb returned 0 as uid
Jan 8 16:08:01 localhost dovecot: imap: Error: Invalid user settings. Refer to server log for more information.
Dovecot won't let you log in as root. Use some other user and userid.

Failed to connect to a valid mail server in liferay

I implement a mail service which works fine with local machine(liferay 6.1 with tomcat).
But when I deploy mail service into server(liferay 6.1 with webSphere server on Linux machine ) It wont work
It gives error as
[liferay/scheduler_dispatch-164][MailEngine:560]
Failed to connect to a valid mail server. Please make sure one is properly configured. Could not connect to SMTP host: smtp.gmail.com, port: 465
Please suggest any solution

Remote host closed connection during handshake exception while sending out mail using Java Mail

I am using Java Mail API Ver. 1.4.2 for sending out email in JSF 1.2-Spring based Web Application. I am using non secured SMTP connection for sending out a mail. This email configuration is working fine standalone. Also verified this utility using JUnit 4 test and I am able to send mail using non secure connection.
When I integrate this email module with main web application I am getting following exception at runtime while sending out a mail.
javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLHandshakeException: Remote host closed
connection during handshake at
com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1764)
at
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1523)
at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:453)
at javax.mail.Service.connect(Service.java:317) at
javax.mail.Service.connect(Service.java:176) at
javax.mail.Service.connect(Service.java:125) at
javax.mail.Transport.send0(Transport.java:194) at
javax.mail.Transport.send(Transport.java:124)
Verified this email module using secure SMTP connection and it's working fine.
Anyone having idea on this issue? Why non-secured SMTP connection not working in integration with Web Application?
I am using email module for both secured and non secured connections.
In that following property was causing the issue : props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Removed this property for non secured connections and now my non-secured SMTP connection is working in integration with Web Application.

Which hostname is required to send email to a user through a website created with Google Apps?

Our website was created with Google Apps.
My website URL is http://mydomain.com, which is pointing to http://sites.google.com/a/mydomain.com/.
I want to send email to a registered user.
I am using the Apache Commons jar to send mail to the user.
I get this error message:
Sending the email to the following server failed : http://mail.google.com/a/mydomain.com:25
I used smtpPortAddress=25 & hostName=http://mail.google.com/a/mydomain.com.
I am not spending money on email server setup, so I want to send email through our website.
Which hostname is required to send mail?
I do not know if you can use port 25, for the encrypted SMTP port you can use
Host: smtp.gmail.com
Port: 465
Authentication: Yes
Username: you#yourdomain.com
Password: #YOUR_PASSWORD#
Security: SSL
Either way, just use smtp.gmail.com with your #yourdomain.com name.
You could use any mail server to sent your mail.
But if you like to use GMail the server is smtp.gmail.com.
But you also will have to make sure you authenticate as a valid gmail user.

Categories