Azure移动服务上的nodemailer无法正常工作 [英] nodemailer on azure mobile service not working

查看:52
本文介绍了Azure移动服务上的nodemailer无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to send mail with nodemailer. The script works on local machine but i am not able to include nodemailer in azure mobile service. Added 'nodemailer' : "*" in my package.json but still not able to include it.

日志说

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

TypeError: Cannot read property 'prototype' of undefined

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

I commented out complete logic but error was still there. Finally commented out var nodemailer = require('nodemailer');

错误消失了.

推荐答案

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

To get around this issue, you need to install an older version of nodemailer so it can work at the Azure mobile service. I added version 0.7.1 of nodemailer in the package.json for Azure, then did the necessary code changes and it worked for me.

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

The code changes that you need to do to support 0.7.1 are very minor, here is the full code from the documentation:

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文档

这篇关于Azure移动服务上的nodemailer无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆