How to use Nodemailer with Google? - gmail

Hello I made a NodeJs backend and I implemented nodemailer. The only issue is I get the error with Invalid Login, because I don't have less secure apps turned on. I know, but I went to google and I clicked on the less secure app section and this is what I get
This setting is no longer available. Learn more
Does anyone solved the error different way and is able to send emails?

When you want to send email over Gmail SMTP, google enable you to set up App password. You have to have set up 2-Step verification in your google account. Once 16 digit password are generated, you just replace password for login (username is your email address, that does not change).
Sources:
Google: Sign in with App Passwords

Related

Python cannot send email from gmail account with smtp

I used gmail account to send email notification when my script fails. Since May 30, 2022, Gmail stops supporting access over Less secure app access
This setting is no longer available.
From Google support:
To help keep your account secure, from May 30, 2022, ​​Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.
I am receiving python error even my user and password is OK (tested by logging to my account):
Authentication error. Wrong user or password.
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials u2-20020a1709061da200b0072f42ca2934sm7507815ejh.148 - gsmtp')
What is the best way how to use google account for notification emails or is there better way or tool how to be notified?
When you want to send email over Gmail SMTP, google enable you to set up App password. You have to have set up 2-Step verification in your google account. Once 16 digit password are generated, you just replace password for login (username is your email address, that does not change).
Sources:
Google: Sign in with App Passwords
Stackoverflow: What's solution for sending emails from python while gmail " the less secure apps " is not enabled anymore

can curl no longer send emails using gmail accounts?

I've been using the following to test that html email templates come through formatted correctly in different clients:
curl --ssl-reqd --url 'smtps://smtp.gmail.com:465' --user '{EMAIL}#gmail.com:{PASSWORD}' --mail-from '{EMAIL}#gmail.com' --mail-rcpt '{EMAIL}#gmail.com' --upload-file {FILE}
And all of a sudden I'm getting "curl: (67) Login denied" - the login details are definitely correct and nothing's changed on my end. My guess is that google is now blocking non SSO email logins?
Don't know if will solve your problem, but if you have enabled 2-Step Verification in your Google account, you have to create some app password
You will have to make a new 16 digits password specific for this application and simply change the account password to this new secure app password. Now you can create one password for each app. It will keep your account password safe and manage app passwords separately.
Login to your account to create it:
https://myaccount.google.com/apppasswords
You must enable the 2-Step Verification (https://myaccount.google.com/signinoptions/two-step-verification) to access this feature.
To help keep your account secure, from May 30, 2022, ​​Google no
longer supports the use of third-party apps or devices which ask you
to sign in to your Google Account using only your username and
password.
https://support.google.com/accounts/answer/6010255

How to send form data to Gmail without using nodemailer

I was trying to get form data to my gmail account so I get to know about 'nodemailer' package but the problem is that it is asking for my gmail password also I have to make my gmail account less secure for this.
Is there any way to get mail without my password?
Use an 'App Password' for this purpose. This is "a 16-digit passcode that gives a less secure app or device permission to access your Google Account". See https://support.google.com/accounts/answer/185833?hl=en

How can I validate SMTP hostname/port/username/password is working on Node.JS?

I have a node.js web application and I'd like its status page to have an indicator if the SMTP settings for the site are functioning. I could send an email and check if it goes across, but I'm wondering if I can do something like a ping for SMTP. Can I, without actually sending an email, check that I can connect to the SMTP server and verify the configured credentials?
I did a little experimenting with the smtp-protocol module (https://npmjs.org/package/smtp-protocol) but was not successful as I couldn't figure out how to use a username/password with the client.
Make verification method by sending email using that current credentials. if email can be sent then by that credentials then it is working fine otherwise it will be incorrect credentials. if it is correct credentials then use it for email sending process

Advantages of XOAUTH2 in nodemailer

The nodemailer module (allows to send emails in a node.js app) supports XOAUTH2 authentication against Gmail accounts. Why would one want to use this for general purpose email notifications as opposed to just specifying the user: and pass: parameters in auth? I understand that the password is then stored in plain text, but it's never propagated anywhere. Also, the XOAUTH2 method seems to require a clientSecret: parameter, which should also probably not be made public. So what are the advantages here?
Similar question: how can I include authentication information in the app without pushing it into the remote repo? Is there a way to just ignore those lines with Git?
Using XOAUTH is useful when you want to send e-mails on behalf of your users (eg. as if the sender would be the user, not your application) - instead of asking their passwords, you can ask them to authorize your application through the OAuth mechanism. The resulting client secrets are known only to you, valid only for accessing the e-mail of the user, nothing more and the user can revoke these client tokens any time they wish.
If you do not want to send mail on behalf your users but with your own credentials, then there is no point of using XOAUTH.

Resources