rekha s
rekha s

Reputation: 617

Send Mail in Node Js

I need to send email using Node Js. I have used the following code,

    var nodemailer = require("nodemailer");
//var smtpTransport = require("nodemailer-smtp-transport")
var smtpTransport = nodemailer.createTransport("SMTP",{
   service: "Gmail",
   auth: {
       user: "[email protected]",
       pass: "xxxxxxxx"
   }
});
smtpTransport.sendMail({
           from: "[email protected]", // sender address
           to: "[email protected]", // comma separated list of receivers
           subject: "Test Mail", // Subject line
           text: "Hi, Test Mail"// plaintext body
        }, function(error, data){

           if(error){
               console.log(error);
           }else{
               console.log("Mail Sent");
           }
        });

When I run this code, I get error,

   { AuthError: Invalid login - 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsO
534-5.7.14 nSiseM4eUKjA64AZjuUfbMQisituUebEXGcWjgh1aePgnHNUs2gNlmIrmDHMY-VHZpi_-_ShO
534-5.7.14 5piXf2MTbZWxaEbFpal3ZqHZlUIvWc8vdCZBhjuhBlzVzALTv0Swes374SR7bwoalfGGIgHI
534-5.7.14 n7mxubIXPM_BM0ehxuh2tqDLL9n3wilsOpyShjhzLZ3hZg_baUdUT2lKp2MBzXRtblrD6nDw
534-5.7.14 hL-u0QueUcDAVi0XsZqjLmmhGozaM> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14  Learn more at
534 5.7.14  https://support.google.com/mail/answer/78754 y205sm10903842pfb.13 - gsmtp
    at SMTPClient._actionAUTHComplete (/var/www/html/node_modules/simplesmtp/lib/client.js:925:23)
    at SMTPClient._onData (/var/www/html/node_modules/simplesmtp/lib/client.js:354:29)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:172:18)
    at TLSSocket.Readable.push (_stream_readable.js:130:10)
    at TLSWrap.onread (net.js:542:20)
  name: 'AuthError',
  data: '534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsO\r\n534-5.7.14 nSiseM4eUKjA64AZjuUfbMQisituUebEXGcW1aePgnHNUs2ghjhNlmIrmDHMY-VHZpi_-_ShO\r\n534-5.7.14 5piXf2MTbZWxaEbFpal3ZqHZlUIvWc8vdCZBuhBlzVzALTvhjh0Swes374SR7bwoalfGGIgHI\r\n534-5.7.14 n7mxubIXPM_BM0ehxuh2tqDLL9n3wilsOpyShzLZ3hZg_bahjUdUT2lKp2MBzXRtblrD6nDw\r\n534-5.7.14 hL-u0QueUcDhjAVi0XsZqjLmmhGozaM> Please log in via your web browser and\r\n534-5.7.14 then try again.\r\n534-5.7.14  Learn more at\r\n534 5.7.14  https://support.google.com/mail/answer/78754 y205sm10903842pfb.13 - gsmtp',
  stage: 'auth' }

I have allowed access to my gmail account using the following link

https://accounts.google.com/b/0/DisplayUnlockCaptcha

But still I am getting this error.Please help.

Upvotes: 1

Views: 924

Answers (2)

cedric maroka
cedric maroka

Reputation: 15

I had the same issue solved..Login to your Google account using a browser, then visit the link below to unlock it: https://accounts.google.com/DisplayUnlockCaptcha

Upvotes: 0

Vibhu Dadhichi
Vibhu Dadhichi

Reputation: 1129

  1. For Gmail you may need to configure "Allow Less Secure Apps" in your Gmail account. Click Here.

  2. If you are using 2FA in that case you would have to create an Application specific password.

  3. You also may need to unlock your account with "Allow access to your Google account" to use SMTP.

I can upload a working example on github if you wish. Authentication is the error here.

Hope it helps.

Upvotes: 3

Related Questions