I am running a Java web application and send email. "mail.smtp.auth: false" in props, but I still keep getting
javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful
What is the best solution? I couldn't find what I was looking for in this thread
properties:
mail.smtp.auth: false
mail.smtp.starttls.enable: false
mail.debug: true
mail.host: xx.xx.xx.x
mail.port: 25
mail.smtp.socketFactory.class: xxxxxx
This is how I edited my settings. But I'm getting authentication error.
javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful
Related
Well there are a lot of discussion on this topic,
but looks like that google enforce its security policy and now, if is it still possible, is hard to find a way to send and mail by the smtp protocol using google
my java application works properly, it is not a fact of code, i use it to send mail by outlook365 or hotmail
the point here is how to configure the properties to pass to the session
Session session = Session.getInstance(prop,auth)
and how to configure the google account to accept an smpt call
to be precise I'm using a google workspace account and not a standard#gmail account
regarding the properties should not be a big doubt, this are listed in several pages of google:
regarding the google account, look like there are 3 strategies:
https://support.google.com/a/answer/176600?hl=en
Option 1: Send email with SMTP relay:
after configured the routing form my domain this is the log received
mail.smtp.starttls.enable=true
mail.smtp.port=587
mail.smtp.auth=true
mail.smtp.host=smtp-relay.gmail.com
mail.smtp.ssl.protocols=TLSv1.2
mail.smtp.ssl.trust=smtp-relay.gmail.com --> in this way a consider valid their certificate
but go head...
DEBUG SMTP: protocolConnect login, host=smtp-relay.gmail.com, user=myuser#my.domain, 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
Caused by: javax.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
Option 2: Send email with the Gmail SMTP server
tested but this is no more possible, google removed in the 2022 the creation of app password
Option 3: Send email with the restricted Gmail SMTP server
not valid approach, you can send only mail in your organization
if sameone succed could be nice to hear
Apps passwords can be used to login to googles smtp server you need to have 2fa enabled on your google account in order to create an apps password.
Simply create an apps password and use it in place of your standard gmail password in your code.
Quick fix for SMTP username and password not accepted error
How to create a Apps Password for connecting to Google's SMTP server.
Another option would be to use XOauth2 and authorize a user to access their gmail account. This can be used if you cant enable 2fa on the account.
When I run my application locally, everything works correct, mails are sent, but I deployed my application to aws EC2 and I get this:
org.springframework.mail.MailAuthenticationException: Authentication failed;
I have less secure apps turned off on my gmail account I send emails from, the two steps verification is also turned off. As I said, everything was working before I deployed the app to aws.
Properties:
mail:
host: smtp.gmail.com
username: <my.mail>#gmail.com
password: <my.password>
port: 587
protocol: smtp
properties:
mail.smtps.auth: true
mail.smtp.starttls.enable: true
mail.smtp.ssl.trust: smtp.gmail.com
Am I missing any property or something like this?
This looks like duplicate from:
javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1
Ok, I finally solved this. The problem is that google blocks EC2 ports so what I needed to do was to turn on 2 steps verification in my google account -> then create new password (option under setting 2 steps verification) -> set this password in my .yml file as the new one -> everything works
I also set the SMTP rules in my EC2 security groups but I am not sure if it had any impact or the steps I have descripted above are enough
In my SpringBoot application i'm using Spring mail to send emails from a Gmail account (i connected through an app password). It was working fine, but after a time (about a week), it stopped working and i got an error telling me thanks username and password didn't match. After i connected to my Gmail account to check if the app password is still active, it started working again.
After another week, it happened again.
My question is : is there any validity time for the application password ? Can i increase it ? Why is it doing this ? How can i solve this ?
The error : 534 5.7.9 https://support.google.com/mail/?p=WebLoginRequired k18sm5238866wms.1 - gsmtp ] with root cause ...
application.properties :
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username= my email
spring.mail.password= the app password
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
Thank you for your help
IMAP is removing the original content from the mail, as can be seen from below example (The original message has been removed from the bounce message.)
Question: Is there any config that I can provide to IMAP while connecting to always send the original message?
Example :
Return-Path: <>
To: a#ba.com
From: Mail Administrator <postmaster#b.com>
Reply-To: <Postmaster#b.com>
Subject: Mail System Error - Returned Mail with Subject: Hi from a
Date: Tue, 11 Oct 2018 12:38:19
Message-ID: <12121213312.AH12R3177.ns12d12121231u2fep03t-svc.1.q.com#qwp03t-q>
MIME-Version: 1.0
Content-Type: multipart/report;
report-type=delivery-status;
Boundary="===========================_ _= 8483766(3177)q"
Content-Transfer-Encoding: 7bit
--===========================_ _= 8483766(3177)q
Content-Type: text/plain
This Message was undeliverable due to the following reason:
Each of the following recipients was rejected by a remote mail server.
The reasons given by the server are included to help you determine why
each recipient was rejected.
Recipient: <a12312121#gmail.com>
Reason: 5.1.1 The email account that you tried to reach does not exist. Please try 5.1.1 double-checking the recipient's email address for typos or 5.1.1 unnecessary spaces. Learn more at 5.1.1 https://support.google.com/mail/?p=NoSuchUser w02-q2.2a60 - gsmtp
Please reply to <Postmaster#a.b.com>
if you feel this message to be in error.
The original message has been removed from the bounce message.
--===========================_ _= 8483766(3177)q
Content-Type: message/delivery-status
Reporting-MTA: dns; asasd.as.aas.a.a.com
Arrival-Date: Tue, 11 Oct 2018 12:38:06
Received-From-MTA: dns; a.a.a.a.b.com
Action: failed
Status: 5.1.1
Remote-MTA: dns; gmail-smtp-in.l.google.com (172.217.194.27)
Diagnostic-Code: smtp; 550-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at
550 5.1.1 https://support.google.com/mail/?p=NoSuchUser w20-v6si34204854plp.260 - gsmtp
--===========================_ _= 8483766(3177)q--
IMAP - internet message access protocol is a protocol to access emails on a mail server. This does not dictate what is provided by the server when an Email is requested via IMAP. I would suggest posting the mail server you are running as there may be configuration settings on the mail server that can do this.
I am facing problem on a centOS server while sending java mails. Getting the following exception.
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25, response: -1
I used the following command from the command prompt and I got the mail as expected.
echo "testing" | mail -s"test subject" shantanu.oa#gmail.com
The relevant entry from maillog looks like this...
Mar 28 20:13:16 postfix/smtpd[10120]: fatal: no SASL authentication mechanisms
Mar 28 20:13:17 postfix/master[28163]: warning: process /usr/libexec/postfix/smtpd pid 10120 exit status 1
Mar 28 20:13:17 postfix/master[28163]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling
Mar 28 20:26:22 postfix/smtpd[11001]: warning: SASL: Connect to private/auth failed: Connection refused
How do I correct the problem?
From the log entry
Mar 28 20:13:16 postfix/smtpd[10120]: fatal: no SASL authentication mechanisms
I suspect that the problem is on Postfix, of which I'm not an expert. Googling for "fatal: no SASL authentication mechanisms" gives lots of interesting links: maybe have a look here or here.
From the exception it seems like its not able to connect to the host.
Have you tried the telnet stuff?
One more thing to check would be whether the name to IP resolution is taking place properly.If not you can use the IP directly in place of host to see what happens.
does your smtp-server needs authentication?
Seems so, because the cmd call with mail works. In default postfix configuration a local user is allowed to send mails without authentication. And your Java application might not be a registered system user on this maschine.
Try to provide username and password in your code to login to the smtp server.