DEV Community

Manu krishnan
Manu krishnan

Posted on • Edited on

nodeMailer after google security update

Node mailer

most of them know Node mailer but with latest security update of google some of them not able to use Node mailer , Don't worry I will help you to resolve your issue ... if you are a beginer you can also follow this documentation....Let's start

step 1

install node mailer in your server

npm install nodemailer

step 2

Add this code

**const nodemailer = require('nodemailer')

const sendmail= async (req, res) => {

const { email } = req.body;

let transporter = nodemailer.createTransport({

host: "smtp.gmail.com",

port: 465,

secure: true,

auth: {

  user: "example@gmail.com",

  pass: "***",

},
Enter fullscreen mode Exit fullscreen mode

});

try {

// send mail using optional parameters

var mailOptions = {

  from: "example@gmail.com",
Enter fullscreen mode Exit fullscreen mode

// here you an replace email with custom email name //

  to: email,



  subject: "Type your e-mail subject here",



  html: `

  <img style="width:100px;height:40px;object-fit:contain" src="https://example/Image/example.jpeg" alt="Yourimge">

    <h2Email recciewvedlick Here  to test </h2>

  `,

};



// get the response

transporter.sendMail(mailOptions, function (error, info) {

  if (error) {

    console.log(error);

  } else {

    console.log("Email sent: " + info.response);



    return res.status(200).json({ success: true, message: info.response });

  }

});
Enter fullscreen mode Exit fullscreen mode

} catch (err) {

console.log(err);
Enter fullscreen mode Exit fullscreen mode

}

};
**

inside auth we need to give password i mentioned in top the google is updated the security information so we need to follow the latest updates

so follow me to get your password

  1. You need to secure your google account with two step verification

  2. next go to this link

** https://myaccount.google.com/apppasswords?pli=1&rapt=AEjHL4NSosO4ykDzkOiQw_CZ7_oQRKcZutIJFw7_S7zLmf5nv0GsqoTSmbNQKJ6YzDuR8DM3sUSMoXQvQ7gVeCdGXuLaZKY-dg
**

  1. Then you add any custom name and then you will get 16 digit password copy that password

and add that password inside the auth in given code above

remember one thing email also replace with your email which created app password

(26
-10-2023)

official documentation : https://nodemailer.com/

If there is still a problem contact me :

https://https://www.linkedin.com/in/manu1305/

whatsapp :+91 8943293217

Top comments (0)