【问题标题】:nodemailer on azure mobile service not workingazure移动服务上的nodemailer不工作
【发布时间】:2015-08-30 21:06:54
【问题描述】:

我正在尝试使用 nodemailer 发送邮件。该脚本适用于本地计算机,但我无法将 nodemailer 包含在 azure 移动服务中。在我的 package.json 中添加了 'nodemailer' : "*" 但仍然无法包含它。

日志说

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

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

错误消失了。

【问题讨论】:

  • 您是否使用相同(或类似)版本的node?您是否在本地使用 nodemailer 0.7 而在远程使用 1.0?能给个完整的stacktrace吗?
  • 你是对的。我的机器的节点版本是 0.10.29,在我的机器上是 0.8.28。知道如何在 azure-mobile-service 上更新 nodejs 的版本吗?或者如何安装与该版本兼容的依赖项。我检查了nodemailer版本,两台机器上都是一样的(1.3.0)。
  • 无法帮助您,抱歉。 According to the developer,nodemailer 0.7.1 是最后一个兼容 0.8 的版本。您需要对代码进行一些更改 - nodemailer 1.x 与 0.x 版本不完全兼容。
  • 您无法升级 Azure 移动服务上的节点版本。它对 0.8.28 有硬依赖。新产品中正在修复此依赖关系,但尚未发布 Node.js 的预览版,您必须将代码库迁移到新的 SDK。

标签: node.js azure azure-mobile-services nodemailer


【解决方案1】:

要解决此问题,您需要安装旧版本的 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 documentation

【讨论】:

    猜你喜欢
    • 2014-06-28
    • 1970-01-01
    • 1970-01-01
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多