繁体   English   中英

Azure移动服务上的nodemailer无法正常工作

[英]nodemailer on azure mobile service not working

我正在尝试使用nodemailer发送邮件。 该脚本可在本地计算机上运行,​​但是我无法在Azure移动服务中包含nodemailer。 在我的package.json中添加了'nodemailer':“ *”,但仍然无法包含它。

日志说

TypeError:无法读取未定义的属性“ prototype”

我注释掉了完整的逻辑,但错误仍然存​​在。 最后注释掉var nodemailer = require('nodemailer');

错误消失了。

要解决此问题,您需要安装旧版本的nodemailer,以便它可以在Azure移动服务上运行。 我在用于Azure的package.json中添加了nodemailer的0.7.1版本,然后进行了必要的代码更改,它对我有用。

支持0.7.1所需的代码更改很小,这是文档中的完整代码:

var nodemailer = require("nodemailer");

// create reusable transport method (opens pool of SMTP connections)
var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
        user: "gmail.user@gmail.com",
        pass: "userpass"
    }
});

// setup e-mail data with unicode symbols
var mailOptions = {
    from: "Fred Foo ✔ <foo@blurdybloop.com>", // sender address
    to: "bar@blurdybloop.com, baz@blurdybloop.com", // list of receivers
    subject: "Hello ✔", // Subject line
    text: "Hello world ✔", // plaintext body
    html: "<b>Hello world ✔</b>" // html body
}

// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response){
    if(error){
        console.log(error);
    }else{
        console.log("Message sent: " + response.message);
    }

    // if you don't want to use this transport object anymore, uncomment following line
    //smtpTransport.close(); // shut down the connection pool, no more messages
});

Nodemailer 0.7.1文档

暂无
暂无

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

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