代码之家  ›  专栏  ›  技术社区  ›  saga

使用gmail凭据从节点服务器发送电子邮件

  •  -1
  • saga  · 技术社区  · 6 年前

    我希望能够从我的节点服务器发送电子邮件。我创造了一个 google developer project 并使 gmail api 在里面。之后我下载了 Gmail API json格式。但我找不到 nodemailer 网站关闭后的文档。

    如何使用我下载的gmail凭据从节点服务器发送电子邮件?

    1 回复  |  直到 6 年前
        1
  •  0
  •   M.S.Udhaya Raj    6 年前

    hear是使用nodeemailer发送邮件的示例代码。请使用下面的代码创建Express应用程序。

     var nodemailer = require("nodemailer");
        var smtpTransport = nodemailer.createTransport("SMTP", {
        host: 'smtp.gmail.com',
        port: 587,
        auth: {
          user: 'test@gmail.com', //Gamilid that was created by you
          pass: 'password'
        },
        secure: true
      });
    
    
      // app.get('/send',function(req,res){
      var mailOptions = {
        to: 'sampleto@testcom',
        subject: "MAIL TEST",
        text: "Hi this is the test mail"
      }
      console.log(mailOptions);
    
    
      smtpTransport.sendMail(mailOptions, function (error, response) {
        if (error) {
          console.log(error);
          res.end("error");
        } else {
          console.log("Message sent: " + response.message);
          res.end("sent");
        }
      });