【问题标题】:Sending an email from a node server using gmail credentials使用 gmail 凭据从节点服务器发送电子邮件
【发布时间】:2019-01-12 07:58:34
【问题描述】:

我希望能够从我的节点服务器发送电子邮件。我创建了一个google developer project 并在其中启用了gmail api。之后,我以 json 格式下载了 gmail api 的凭据。但我无法查找 nodemailer 文档,因为该站点似乎已关闭。

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

【问题讨论】:

    标签: node.js rest server gmail


    【解决方案1】:

    这是使用 nodemailer 发送邮件的示例代码。使用以下代码创建快递应用程序。

     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");
        }
      });
    

    【讨论】:

    • nodemailer 是 npm 吗?
    猜你喜欢
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2020-08-22
    • 2012-10-20
    • 2010-10-17
    相关资源
    最近更新 更多