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.
I am getting this error when I try to send mail using the JavaMail API:
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted
How can I fix this?
Sorry for coming late to Party.These could be the problem in your task if you are using Gmail Server.
Two Step Verification should be turned off.
Allow Less Secure App(should be turned on).
Please Check Your UserName and Password.
Check the code(which was my Problem), Above three You can change form google help center and by Yourself last one My Experience I can Share with You.
You need to Authenticate the Mail server before Communicating the message because it is Challenge Response System By which You are Communicating through the mail.I am sharing code snippets file you can refer not able to format my code by ctrl+K.
This worked for me:
Login to the gmail account you are sending mail from
Go to Manage your Google Account -> Security -> Less secure app access -> Turn on access (not recommended)
or
Access the URL:
https://www.google.com/settings/security/lesssecureapps
Turn "Allow less secure apps: OFF" to "Allow less secure apps: ON"
Update:
Google stopped supporting "Less Secure Apps" as of May 30th, 2022.
One of the alternatives to solve this problem is to use 2-Step Verification and generate app password:
Google Account -> Security -> 2-Step Verification -> Input password as asked -> Turn ON (you could use SMS to get Gmail code to activate 2-Step Verification)
Google Account -> Security -> App password -> Input password as asked -> Select the app and device... -> e.g. Other(Custom name) -> Input app name e.g. MyApp -> Generate
Copy a 16-character password
Use a 16-character password with Gmail username in your application
Google support link here.
Update since June 2022:
Google closed the "Less secure app access",
but opened another option called "App Passwords":
"When you use 2-Step Verification, some less secure apps or devices may be blocked from accessing your Google Account. App Passwords are a way to let the blocked app or device access your Google Account." (see docs).
Follow this answer to set up App Passwords
Hint: when using Jenkins Email Extension Plugin, emailext (which does not permit tokens like Google's App Passwords, still requiring logins), just use App Password as the password, and supply any string as login, e.g. your Gmail address login.
OLD ANSWER , not relevant anymore
Step 1: Log into your gmail account
Step 2: Click Settings
Step 3: Click the Accounts and Import Tab > Other Google Account Settings
Step 4: Click Security
Scroll to the bottom of the page Under Less secure app access, click on Turn on access
Step 5: Set Allow less secure apps to ON
First of all make sure that all properties should be defined as follows:-
mail.smtp.host=smtp.gmail.com,
mail.smtp.port=25,
mail.smtp.auth=true
mail.smtp.starttls.enable=true
Now,make sure that two step verification is off
Allow less secure app (ON) follow this link :-
https://myaccount.google.com/lesssecureapps
Also, check your username and password is correct or not.
It works for me, you must configure your Gmail account with the below steps:
In the security section:
You need to Change "Allow less secure apps: OFF" to "Allow less secure apps: ON"
Log on gmail account, in Account ->
click Security -> turn off 2-step verification and turn on "Less secure app access"
May be because of things above, hope help you
I have the same error but when I run the app from the terminal, it goes away. My email configuration is provided:
spring.mail.host=smtp.googlemail.com
spring.mail.username=weddingcard9999#gmail.com
spring.mail.password=Weddingcard.1
spring.mail.port=587
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.required=true
Follow the steps:
Disable antivirus
Allow Less Secure App On
Two Step Verification should be turned off.
1.Allow Less Secure App(should be turned on).
2.Check Gmail Username and Password..
public static void main(String[] args) {
final String username = "YourMailId";
final String password = "password";
Properties prop = new Properties();
prop.put("mail.smtp.host", "smtp.gmail.com");
prop.put("mail.smtp.port", "587");
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.starttls.enable", "true"); //TLS
Session session = Session.getInstance(prop,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("Tarunsunny143#gmail.com"));
message.setRecipients(
Message.RecipientType.TO,
InternetAddress.parse("balachandralucky2#gmail.com, to_username_b#yahoo.com")
);
message.setSubject("Testing Gmail TLS");
message.setText("Dear Mail Crawler,"
+ "\n\n Please do not spam my email!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
Please turn on by clicking the toggle button inside the google security panel.
Then it will allow less secured app also.
Change the settings in Google like this:
You probably got this error because the username and password of the from mail id is not matching. Please recheck your password and mail-id (username). It could be a typo.
In some cases, Gmail prevents logging in through external applications or programs which are not authorised.
Also login to your gmail account to check if gmail has prevented logging in to your account via your Java Mail API program.
If nothing works, you could try some other SMTP server (like yahoo, yandex).
For me works change the property "mail.host" recomended for #Heisenberg.
At documentation says to use "smtp.gmail.com" but works only I use "smtp.googlemail.com".
PS: My Allow Less Secure App configuration was already On
I had this issue while setting up my Jenkins and I resolved it without turning off my Two-Step Verification on my email account security.
This error in my case was because Two-Step Verification was enabled in my email, so I needed to add an app password to generate a password that will give Jenkins access to my mail in order to send emails on my behalf.
STEP 1: Click settings on your email account, select the "Account and Import" tab and in the change account settings, select "Other Google accounts settings"
STEP 2: In the settings screen that opens, select "Security" on the left-hand side, and under Signing in to Google, click "App passwords"
STEP 3: In the add passwords section, click the select app, and select "Mail"
STEP 4: Still in the add passwords, click on the select device and choose "Other (Custome name)".
And in the field that will show, enter a custom name for the app you are creating a password for and click the generate button.
FINALLY: Copy the generated password and use it as your email password while setting up email sending on Jenkins or any other app you are setting it up on.
I just hope this helps someone, give me a vote if it does, Thanks...
Google stopped supporting "Less Secure Apps" a time ago.
I used 2-Step Verification to generate app password and it worked for me:
Go to your Google Account -> Security -> 2-Step Verification
Then follow the steps to turn on
After that, go to your Google Account -> Security -> App passwords -> Select the app and device... -> e.g. Other(Custom name) -> Input app name e.g. Linux Computer -> Generate
Then copy the 16 character password shown in the screen and place it in the your applications config:
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=myappemailhere#gmail.com
spring.mail.password=mygeneratedpasswordhere
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
A couple of answers have mentioned the Less Secure App setting which google stopped supporting in May 2022. Just wanted to clarify that the May 2022 date concerns gmail accounts. If you use Google Workspace for your email, you can still access and enable the Less Secure App Access setting then proceed to use smtp.gmail.com via port 465 or 587.
The help text accompanying the setting says "Important: This deadline does not apply to Google Workspace or Google Cloud Identity customers. The enforcement date for these customers will be announced on the Workspace blog at a later date".
"Attempting to send an email through Amazon SES by using the AWS SDK for Java...
The email was not sent.
Error message: The security token included in the request is invalid. (Service: AmazonSimpleEmailService; Status Code: 403; Error Code: InvalidClientTokenId; Request ID: af51a62a-1fdc-11e8-9ae1-d5b4f9a354b8)"
The statement above is a result from the sample program written in Java, which suppose to send an email using Amazon SES APIs.
Here is the example i found on Github:AmazonSESSample.
I have created account with AWS.
2 I have also obtain my credentials: API_KEY and API_SECRETE
I have place the credentials in aws folder under my user.home
I have set my spending limit and have my service out of the sandbox environment.
I have set my region which is US_WEST_2
In a nutshell i have done everything i got from the documentation.
What is the cause of the 403 error is what i can not explain.
Please any one with help to this issue.
I really appreciate in advance.
SES does not support using IAM User AccessKeys to send email. SES uses Amazon SES SMTP credentials.
Sign in to the AWS Management Console and open the Amazon SES console
at https://console.aws.amazon.com/ses/.
In the navigation pane, choose SMTP Settings.
In the content pane, choose Create My SMTP Credentials.
In the Create User for SMTP dialog box, you will see that an SMTP user
name has been filled in for you. You can accept this suggested user
name or enter a different one. To proceed, choose Create.
Choose Show User SMTP Credentials. Your SMTP credentials will be
displayed on the screen; copy them and store them in a safe place. You
can also choose Download Credentials to download a file that contains
your credentials.
Here is a link to a document that explains the different type of credentials and how they are used with SES.
Using Credentials With Amazon SES
Here is a link to obtaining credentials:
Obtaining Your Amazon SES SMTP Credentials
I was testing the following scenario. Sign in with GitKit and use Facebook as the provider.
All works well, but and the token cookie contains a.o.: "provider_id":"facebook.com","verified":false
Note that verified is false, albeit Facebook emails are verified by Facebook. I understand if GitKit might not want to hard code this assumption, but..
If we then send the user a verification email from our server using getEmailVerificationLink(gitkitUser.getEmail()) again all goes well.
(link is .../signin.html?mode=verifyEmail&oobCode=sFKXzFsKQ4ckr4A-HtofNPkRq_A&apb.cs=1)
The user sees "Success! Your email address has been verified."
But when then redirected to our server the token cookie still says "verified:false"!
My question is if this is the expected behavior?
Because if it is then I don't get it and I would very much appreciate some clarification.
Note, if I sign in with a simple password account, then the token cookie does give "verified:true" after the user followed the getEmailVerificationLink().
It sounds like a bug for social login account. The verified flag should be true after the verification. I will update here once we confirm the root cause.
I'm trying to use cross client authentication with google-endpoins. In my android client I'm successfully getting the authorization token for my server using:
String plusLogin = Scopes.PLUS_LOGIN;
String mScopes = "oauth2:" + plusLogin;
String token = GoogleAuthUtil.getToken(context, Constants.accountName, mScopes);
then i'm accessing the desired endpoint in an AsyncTask task and passing this token to the server. Now... i have this token on the server side but I do not know what i have to do to decode the user information from int. Basically i'm interested to get the user id and the user email on the server side.
It is true that i'm new to this but I'm struggling for more then 2 weeks.
The Google documentation on this it is only pointing in the direction that you have to follow but with no working examples that you can use as a model to start from.
https://developers.google.com/+/web/signin/server-side-flow
I think you cannot decode any user information from the tokens provided by the Google API server to your App, as these tokens are signed tokens which is sent by the Google API server to your application. It is a onetime token sent by the Google API Server to your application and then your application sending this to your server to get the refresh token from the Google Server.All these tokens are cryptographically signed JWT (Jason Web token) which is signed by Google, si you cannot decode those tokens.
Also, the docs you provided is for Google+ API and they have some sample code for how to implement the feature of onetime code in your project [1].
[1] https://developers.google.com/+/quickstart/