Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Security Alert With Node Mailer

I am having an issue with my portfolio site, which is currently coded using Node and Express. I am using Nodemailer with Google's SMTP for my contact form. My code is all working, my problem is actually with Google.

Sometimes the emails from my contact form will go through no problem. Other times, people will get an error because Google will send me a "Critical Security Alert" for my connected account (thus not allowing the SMTP to log in). I have already enabled less secure apps. I have searched for hours for an answer and cannot find one anywhere.

This is what my createTransport() function looks like (I have changed the email and password):

const smtpTrans = nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
        user: "[email protected]",
        pass: "example"
    }
})

Anyone know how I can fix this?

like image 620
Scotty Olthoff Avatar asked Jun 05 '26 16:06

Scotty Olthoff


1 Answers

You need to log in your Google account and then go to https://myaccount.google.com/lesssecureapps. In that web you should set the switch to ON (should be OFF the first time you enter) so that it allows other applications to access your account

like image 117
Ignacio Ara Avatar answered Jun 07 '26 22:06

Ignacio Ara