简体   繁体   中英

nodemailer on azure mobile service not working

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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