Home > Back-end >  how to fix sign in error with nodemailer in replit
how to fix sign in error with nodemailer in replit

Time:10-22

I am trying to use nodemailer on replit, and I am having some issues here is my code:

const transporter = nodemailer.createTransport({
    service: 'gmail', 
    user: 'email',
    pass: 'password'
});

const mailOptions = {
    from: 'SENDER-EMAIL',
    to: 'RECIPIENT-EMAIL',
    subject: 'SUBJECT',
    text: 'EMAIL BODY',
};
transporter.sendMail(mailOptions,(err,res)=>{
    if(err){
        console.log(err);
    }
    else {
        console.log('The email was sent successfully');
    }
});

obviously I don't have "email and "password" in my code but I don't want to put my actual credentials in here.

I have tried several forms of this, and every question and troubleshooting guide I have seen has said that I either need to disable 2fa, or allow less secure apps to sign in, but I have done both, and it still give me an error saying:

"Error: Mail command failed: 530-5.7.0 Authentication Required. Learn more at 530 5.7.0 https://support.google.com/mail/?p=WantAuthError h19-20020a05620a401300b006eed47a1a1esm9834891qko.134 - gsmtp"

why is this happening still?

CodePudding user response:

Your user and password need to be in an auth property:

const transporter = nodemailer.createTransport({
  service: 'gmail', 
  auth: {
    user: 'email',
    pass: 'password'
  }
});
  • Related