nodemailer on azure mobile service not working

瘦欲@ 提交于 2020-02-05 09:13:59

问题


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.

Logs says

TypeError: Cannot read property 'prototype' of undefined

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

and error was gone.


回答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.

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 documentation



来源:https://stackoverflow.com/questions/26753793/nodemailer-on-azure-mobile-service-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!