在Meteor.js应用程序中使用nodemailer运行批量电子邮件

时间:2017-08-18 10:54:22

标签: node.js email meteor nodemailer

我正在尝试在应用程序中使用nodemailer。在这里跟踪了一个SO线程Is it possible to to send bulk pre-rendered email via the SendGrid API?后,我继续收到以下错误,表明这是一个版本问题。正如nodemailer页面上所述,需要版本6-向上,目前我在版本7.4.0上运行,但仍然收到错误。

这是我的实施:

var nodemailer = require("nodemailer");

if (Meteor.isServer) {
    Meteor.methods({
        MassMail: function () {
            var smtpTransport = nodemailer.createTransport("SMTP",{
                service: "Gmail",
                auth: {
                    user: "mygmailaccount@gmail.com",
                    pass: "mygmailpassword"
                }
            });

            var collections = CollectionName.find({userId: this.userId});
           // var users = getAllUsersAsArray();

            // Loop through your users
            collections.forEach(function (collection){

                // Setup the message
                var mailOptions = {
                    from: "no-reply@christdoes.com",
                    to: students.useremail,
                    subject: subjectTemplate.render(collection),
                    text: textTemplate.render(collection),
                    html: htmlTemplate.render(collection)
                }

                // Send mail
                smtpTransport.sendMail(mailOptions, function(error, response){
                    if(error){
                        console.log(error);
                    }else{
                        console.log("Message sent: " + response.message);
                    }
                });

            });
        }
    });
}

这是控制台上的错误

W20170818-10:42:01.023(1)? (STDERR) C:\Programs\contract\schoolapps\node_modules\nodemailer\lib\mailer\index.js:31
W20170818-10:42:01.024(1)? (STDERR)             compile: [(...args) => this._convertDataImages(...args)],
W20170818-10:42:01.025(1)? (STDERR)                        ^^^
W20170818-10:42:01.034(1)? (STDERR)
W20170818-10:42:01.040(1)? (STDERR) SyntaxError: Unexpected token ...
W20170818-10:42:01.041(1)? (STDERR)     at exports.runInThisContext (vm.js:53:16)
W20170818-10:42:01.043(1)? (STDERR)     at Module._compile (module.js:373:25)
W20170818-10:42:01.044(1)? (STDERR)     at Object.Module._extensions..js (module.js:416:10)
W20170818-10:42:01.046(1)? (STDERR)     at Module.load (module.js:343:32)
W20170818-10:42:01.047(1)? (STDERR)     at Function.Module._load (module.js:300:12)
W20170818-10:42:01.049(1)? (STDERR)     at Module.require (module.js:353:17)
W20170818-10:42:01.051(1)? (STDERR)     at require (internal/module.js:12:17)
W20170818-10:42:01.053(1)? (STDERR)     at Object.<anonymous> (C:\Programs\contract\schoolapps\node_modules\nodemailer\lib\nodemailer.js:3:16)
W20170818-10:42:01.059(1)? (STDERR)     at Module._compile (module.js:409:26)
W20170818-10:42:01.061(1)? (STDERR)     at Object.Module._extensions..js (module.js:416:10

1 个答案:

答案 0 :(得分:1)

您无法更新node中使用的meteor,因此解决方案是安装babel transpiler:

meteor npm install --save babel-runtime