首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Meteor.js应用程序中使用nodemailer运行批量电子邮件

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

Stack Overflow用户
提问于 2017-08-18 18:54:22
回答 1查看 248关注 0票数 0

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

这是我的实现:

代码语言:javascript
复制
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);
                    }
                });

            });
        }
    });
}

这是控制台上的错误

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2017-08-18 20:12:37

您不能更新meteor中使用的node,因此解决方案将是安装babel转发器:

代码语言:javascript
复制
meteor npm install --save babel-runtime
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45754950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档