node.js - Error when sending email using nodemailer -
i'm trying set nodemailer app i'm creating. i'm receiving error when try , run code.
this setup:
const nodemailer = require("nodemailer"); const xoauth2 = require("xoauth2"); var transporter = nodemailer.createtransport({ service: 'gmail', auth: { xoauth2: xoauth2.createxoauth2generator({ user: '****@gmail.com', clientid: '*******************************', clientsecret: '*****************************', refreshtoken: '*****************************' }) } }); var mailoptions = { from: 'dave <*******@gmail.com>', to: '*******@gmail.com', subject: 'nodemailer test', text: 'hello world' } transporter.sendmail(mailoptions, function(err, res) { if (err) { console.log(err); } else { console.log('email sent'); } })
obviously, i've double checked client id
, secret
, refresh token
. following error:
{ error: invalid login: 535-5.7.8 username , password not accepted. learn more @ 535 5.7.8 https://support.google.com/mail/?p=badcredentials y22sm6749013wry.51 - gsmtp @ smtpconnection._formaterror (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp-connection/index.j s:557:19) @ smtpconnection._actionauthcomplete (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp-connection/ index.js:1248:34) @ smtpconnection._responseactions.push.str (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp-conn ection/index.js:340:26) @ smtpconnection._processresponse (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp-connection/ind ex.js:706:20) @ smtpconnection._ondata (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp-connection/index.js:5 09:14) @ tlssocket._socket.on.chunk (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp- connection/index .js:461:47) @ emitone (events.js:96:13) @ tlssocket.emit (events.js:188:7) @ readableaddchunk (_stream_readable.js:176:18) @ tlssocket.readable.push (_stream_readable.js:134:10) @ tlswrap.onread (net.js:551:20) code: 'eauth', response: '535-5.7.8 username , password not accepted. learn more at\n535 5.7.8 https://support.google.com/mail/?p=badcrede ntials y22sm6749013wry.51 - gsmtp', responsecode: 535, command: 'auth plain' }
this first time i've tried using nodemailer , feel i'm missing key piece here not sure what.
new error when using real email , password:
{ error: invalid login: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=akgnsbvz 534-5.7.14 vx8swywncimlbvsoc9zlfxi_9pku2judkwdpy4cjngqct2l0qjkfr3af_slavcv816xj-8 534-5.7.14 ec36n8fzzitno-gnjdvwrsf6eixfeu_ohzp07tc4s3la0x2k9xprwajmlswfnoa1iz2gwx 534-5.7.14 aybkjwt8nmd-wpnnk5j_bn9f3oi56xfafw0nmjxknufhhxpots0sgcc6ern_9hgyp2tyfe 534-5.7.14 mad2gvxdcvp5o9v-yuga9nrch8ey4> please log in via web browser , 534-5.7.14 try again. 534-5.7.14 learn more @ 534 5.7.14 https://support.google.com/mail/answer/78754 f135sm7148225wmd.7 - gsmtp @ smtpconnection._formaterror (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp- connection/index.js:557:19) @ smtpconnection._actionauthcomplete (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp- connection/index.js:1248:34) @ smtpconnection._responseactions.push.str (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp-connection/index.js:340:26) @ smtpconnection._processresponse (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp-connection/index.js:706:20) @ smtpconnection._ondata (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp-connection/index.js:509:14) @ tlssocket._socket.on.chunk (/home/ubuntu/workspace/nufc/nufc_blogv1.2/node_modules/nodemailer/lib/smtp-connection/index.js:461:47) @ emitone (events.js:96:13) @ tlssocket.emit (events.js:188:7) @ readableaddchunk (_stream_readable.js:176:18) @ tlssocket.readable.push (_stream_readable.js:134:10) @ tlswrap.onread (net.js:551:20)
code: 'eauth', response: '534-5.7.14 please log in via web browser and\n534-5.7.14 try again.\n534-5.7.14 learn more at\n534 5.7.14 https://support.google.com/mail/answer/78754 f135sm7148225wmd.7 - gsmtp', responsecode: 534, command: 'auth plain' }
you need set transporter differently, using actual email
, password
of real google account.
// create reusable transporter object using default smtp transport let transporter = nodemailer.createtransport({ service: 'gmail', auth: { user: 'somerealemailaddress@gmail.com', //email address send pass: 'somerealemailpassword' //the actual password account } });
Comments
Post a Comment