简体   繁体   English

在节点J中发送邮件

[英]Send Mail in Node Js

I need to send email using Node Js. 我需要使用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: "example@gmail.com",
       pass: "xxxxxxxx"
   }
});
smtpTransport.sendMail({
           from: "example@gmail.com", // sender address
           to: "example@gmail.com", // 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 我已经允许使用以下链接访问我的Gmail帐户

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

But still I am getting this error.Please help. 但我仍然得到这个错误。请帮助。

  1. For Gmail you may need to configure "Allow Less Secure Apps" in your Gmail account. 对于Gmail,您可能需要在Gmail帐户中配置“允许安全性较低的应用” Click Here. 点击这里。

  2. If you are using 2FA in that case you would have to create an Application specific password. 如果您在这种情况下使用2FA,则必须创建特定应用程序的密码。

  3. You also may need to unlock your account with "Allow access to your Google account" to use SMTP. 您还可能需要通过“允许访问您的Google帐户”来解锁您的帐户才能使用SMTP。

I can upload a working example on github if you wish. 如果你愿意,我可以在github上传一个工作示例。 Authentication is the error here. 身份验证是错误。

Hope it helps. 希望能帮助到你。

我解决了相同的问题。使用浏览器登录到您的Google帐户,然后访问以下链接解锁: https ://accounts.google.com/DisplayUnlockCaptcha

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM