Nodemailer: response: '535-5.7.8 Username and Password not accepted - email

With the shut down of Less secure apps by Google on May 30, 2022, using Gmail with nodemailer now throws an error that says response: '535-5.7.8 Username and Password not accepted. Learn more at\n' + '535 5.7.8 https://support.google.com/mail/?p=BadCredentials. The Nodemailer docs appears to not be updated yet regarding this issue of Less secure apps but suggest to use another delivery provider. I used to just turn on LSA, store the credentials in an environment variable and let nodemailer do its thing, with this change, how can one still use gmail with nodemailer? There are no youtube tutorials to fix this yet and looking at the google documentation, it doesn't show nodemailer

Solved it by creating App password inside Google account. You must have 2-step verification actived.

Open Mail > Settings > See all Settings > Forwarding and POP/IMAP.
Enable POP download: & Enable IMAP access: (then save the settings). Mail Settings Image
Open Your Gmail Account > security > 2-step verification(enable it).
Go to App Passwords > select device > select app(you can create any custom app).
Copy App Password and use it in your application.

You should look into xoauth Nodemailer appears to support serval oauth options
let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
type: "OAuth2",
user: "user#example.com",
clientId: "000000000000-xxx0.apps.googleusercontent.com",
clientSecret: "XxxxxXXxX0xxxxxxxx0XXxX0",
refreshToken: "1/XXxXxsss-xxxXXXXXxXxx0XXXxxXXx0x00xxx",
accessToken: "ya29.Xx_XX0xxxxx-xX0X0XxXXxXxXXXxX0x",
expires: 1484314697598,
},
});

Related

GitHub device verification email not received

After reinstalling windows on my machine, i have tried to login to my Github account using the same user-name password stored in the browser with my Microsoft account...
with Sign in to GitHub
Username or email address page:
its seems to accept the credentials (tried with email as well with username) and then navigate to the next page saying:
Device verification code
We just sent your authentication code via email to y**************#hotmail.com.
But I never receive any email!!!
not in inbox or junk email beside the GitHub Community Summary..
i am afraid to try the Forgot password option - because perhaps it get the auth issue even worse.
Resetting the password seems to be a solution.
The email should arrive within a few minutes in case of setting a new password, even if you had problems in the authentication process.

Forward email using MailKit

I am trying to email EML files via Gmail SMTP server using MailKit. I followed example provided by jstedfast to build MimeMesage and send via Gmail SMTP server. I am able to send email using both the simple authentication using (user account, user password) and using OAUTH2. I followed example how to Setting up OAuth2 for use with Google Mail and all works fine, except that it seems that I have to configure access Scopes to include "https://mail.google.com/"
var accessScopes = new[]
{
"https://mail.google.com/",
"https://www.googleapis.com/auth/gmail.send"
};
otherwise sending fails with the following error:
535: 5.7.8 Username and Password not accepted. Learn more at
5.7.8 https://support.google.com/mail/?p=BadCredentials c5sm231676iod.25 - gsmtp
I assumed that I need to configure access scope with the gmail.send only but it doesn't seem to work.
"https://www.googleapis.com/auth/gmail.send"
I don't want to configure "https://mail.google.com/" which implies full access to the gmail account. When the consent screen is presented to users, users may hesitate to accept all access scopes which seems to be required otherwise sending of mails fails.
I tried to configure some of the read only scopes instead of "https://mail.google.com/" but it doesn't seem to work.
What I am missing?
Thank you
The "https://mail.google.com/" scope is the only scope that works with SMTP, POP3 and/or IMAP.
All of the other scopes are only available to use with the Google REST APIs.

Send an email on Sails.JS using Mailgun?

I'm trying to send an email on Sails.JS but I don't know how to do it. I saw a lot of tutorials but none of the tutorials helped me to send an email. I can send an email with the console using curl.
I tried to configure Mailgun but I don't have a Domain. I'm trying to do it free and I'm also very new on Mailgun and Sails.JS. My purpose is to send an email on Sails.JS, but I don't know how.
Follow the steps below to send email from sailsjs using mailgun
Install mailgun module
npm install mailgun-js --save
Create custom variables in config/custom.js file
mailgunDomain: 'yourmailgundomain',
mailgunSecret: 'yourmailgunkey',
mailgunFrom:'yourmailgunfrommail',
Create a helper
sails generate helper send-single-email
var mailgun = require('mailgun-js')({apiKey: sails.config.custom.mailgunSecret, domain: sails.config.custom.mailgunDomain});
module.exports = {
friendlyName: 'Send single email',
description: '',
inputs: {
options:{
type:'json'
}
},
exits: {
},
fn: async function (inputs, exits) {
mailgun.messages().send(inputs.options, function (error, body) {
if(error){
return exits.error(error)
}
// All done.
return exits.success(body);
});
}
};
Call your helper from any controller
await sails.helpers.mail.sendSingleEmail({
to:'destination#email.com',
from:sails.config.custom.mailgunFrom,
subject:'Subject',
text:'Your message'
})
To use Mailgun, you'll need to sign up for an account. (While this is a paid service at higher usage levels, you should be able to use Mailgun as much as you need to in development without having to provide any credit card information.)
After you've created an account, you'll need to add your Mailgun domain and API secret to your custom config. (In development, this will be either in config/custom.js, or in a local.js file you add to your config/ folder. For your staging or production deployment, you'll want to set these using system environment variables -- aka "config variables" in Heroku.)
If you already own a domain for your app, you can follow Mailgun's instructions for configuring a sending domain.
Otherwise, to send emails from this app without configuring a sending domain, you can use the sandbox domain & test API secret that comes with your Mailgun account. Just be sure to configure the authorized recipents for your sandbox domain first, or there will be errors from the endpoints that attempt to send emails.
~~Copied from Sails.js FAQ page when downloading a new app

Discourse with sendgrid smtp: [Sender] 550 Unauthenticated senders not allowed

I have looked through every single bit of documentation I can find on this matter, and cannot figure this out. There must be people out there using Sendgrid as SMTP for discourse blogs, but I cannot figure out how.
Here's my app.yml setup:
env:
LANG: en_US.UTF-8
# DISCOURSE_DEFAULT_LOCALE: en
UNICORN_WORKERS: 3
DISCOURSE_DEVELOPER_EMAILS: 'admin#my_domain.com'
DISCOURSE_HOSTNAME: 'my_domain.com'
DISCOURSE_RELATIVE_URL_ROOT: /forum
## TODO: The mailserver this Discourse instance will use
DISCOURSE_SMTP_ADDRESS: smtp.sendgrid.net
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: apikey
DISCOURSE_SMTP_PASSWORD: API_KEY
DISCOURSE_SMTP_ENABLE_START_TLS: true
Obviously my_domain and API_KEY are replaced for the proper values. I have triple checked that these things are correct. I have rebuilt the app via launcher rebuild app many times.
The discourse admin UI shows these settings:
However, when I try to send any email, I get a popup that says:
There was a problem sending the test email. Please double-check your mail settings, verify that your host is not blocking mail connections, and try again.
The actual logs on the server aren't very helpful:
Sent mail to test#my_email.com (91.2ms)
Completed 422 Unprocessable Entity in 287ms (Views: 0.2ms | ActiveRecord: 0.4ms)
But when I check the "Skipped" tab of the admin email UI, I see that the "Skip Reason" is [Sender] 550 Unauthenticated senders not allowed - so I assume this is an authentication problem with SendGrid. How can I resolve this?
"Unauthenticated Senders not allowed" is a SendGrid-specific error that explicitly means that your system isn't sending the AUTH command. So even though you have authentication plain set, something is overriding that, and not attempting to authenticate when connecting to SendGrid.
Have you enabled "Mail Send" for that API Key?

Connection error: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser

I am using a php script to connect imap.gmail.com, I have a paid google app account. It was working but after some time I am getting following error
it says I have to login from browser but my CentsOS vps server does not have a browser its command prompt only
I am using mydomain.com
Fatal error: Uncaught exception 'ImapMailboxException' with message 'Connection error: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: https://support.google.com/mail/acco' in /xxxxxx/classes/ImapMailbox.php:51 Stack trace: #0 /home/theluxla/public_html/_backoffice/mailpilot/classes/ImapMailbox.php(42): ImapMailbox->initImapStream() #1 /xxxxxx/classes/ImapMailbox.php(114): ImapMailbox->getImapStream() #2 /xxxxxx/mail.v3.php(28): ImapMailbox->searchMailbox('ALL') #3 {main} thrown in/xxxxx/classes/ImapMailbox.php on line 51
Google replied to me:
Thank you for your message. I understand you're having issues connecting your application with our IMAP server, I'll be happy to help. I didn't want to bother with a call this early, reason why, I'm sending this email instead
In this case, it seems this error is related to the access to "Less secure apps" disabled for the user you're trying to connect via IMAP. Please follow these steps to solve this issue:
In your Admin Console, follow the steps available at this support article https://support.google.com/a/answer/6260879?hl=en under the section "Enabling less secure apps to access accounts".
Log in as the affected user and follow the steps to "Allow less secure apps to access your account" as described at this support article https://support.google.com/accounts/answer/6010255.
I hope this information is helpful. Your case will remain open for three business days and it will auto close if no reply is received. Feel free to reply to this message if you need more help, I'll be happy to continue assisting you.
Sincerely,
David
In may case, Gmail block my server IP
So do the below step to solve this thing.
You need to first Sign in - Google Accounts
https://accounts.google.com
You probably need to go here and follow the instructions:
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Change Gmail accounting setting:-
Enable IMAP.
Status: IMAP is enabled
https://myaccount.google.com/u/2/security-checkup?utm_source=google-account&utm_medium=web&continue=https%3A%2F%2Fmyaccount.google.com%2Fu%2F2%2Fsecurity
In the “Third-party access” tab turn ON less secure app access
Try to access, you will still be denied
https://myaccount.google.com/u/2/security-checkup?utm_source=google-account&utm_medium=web&continue=https%3A%2F%2Fmyaccount.google.com%2Fu%2F2%2Fsecurity
in the “Recent security events” tab you will find a note about your last access, tell that it was you and you will be able to access
In my case none of the proposed answers helped. All options were checked: IMAP -enabled, Less secure apps - enabled, this instruction: https://accounts.google.com/b/0/DisplayUnlockCaptcha also didn't work.
POSSIBLE PROBLEM: use of multiple Gmail accounts (when you connected to many Gmail account and can switch connections). Also if you use the browser like Chrome with profile signed to one of the Google Accounts. In my situation the instruction: https://accounts.google.com/b/0/DisplayUnlockCaptcha didn't work, because I was primarily using browser Chrome profile of my personal Google account, but was working on connection 3rd party app that was using another Google account.
MY SOLUTION. I've added another Chrome profile (corresponding to 3rd Party Gmail Account), switched from my personal profile to working one. And only after that the instruction of https://accounts.google.com/b/0/DisplayUnlockCaptcha gave the positive result. Hope it will save few hours for you.