无法读取未定义的属性“createTransport”

时间:2014-11-23 00:31:02

标签: javascript email meteor nodemailer

我正在测试使用meteor js和nodemailer插件发送电子邮件:

meteor add mrt:meteor-nodemailer

当页面加载时,我在导航器的控制台中看到错误: 无法阅读属性' createTransport'未定义的。

那么问题是什么?

这是代码:

///////////////////////////////////////////


var nodemailer = Nodemailer;

var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
        user: "myname@gmail.com",
        pass: "mypass"
    }
});

var emailNodemailer = function() {

    // setup e-mail data with unicode symbols
    var mailOptions = {
        from: "Sender Name ✔ ", // sender address
        to: "someone@yahoo.fr", // list of receivers
        subject: "Hello ✔", // Subject line
        text: "Hello world ✔", // plaintext body
        html: "Hello world ✔" // 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
    });

};

///////////////

1 个答案:

答案 0 :(得分:0)

这对我有用import * as nodemailer from 'nodemailer';