本文介绍了在Meteor.js应用程序中使用nodemailer运行批量电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在应用程序中使用nodemailer。在遵循SO线程之后,在此处,我不断收到以下错误消息,提示它是版本问题。如在nodemailer页面上所述,要求版本6或更高版本,目前我正在版本7.4.0上运行,并且仍然出现错误。
I am trying to use nodemailer in an application. After following an SO thread here Is it possible to to send bulk pre-rendered email via the SendGrid API?, I kept on getting the below error which suggested it is a version problem. As stated on the nodemailer page that version 6- upward is required, and presently I'm running on version 7.4.0, and still getting the error.
这是我的实现:
var nodemailer = require("nodemailer");
if (Meteor.isServer) {
Meteor.methods({
MassMail: function () {
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
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: "[email protected]",
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
推荐答案
您无法更新流星
中使用的节点
,因此解决方案将是安装 babel
转译器:
You can't update the node
used in meteor
, so solution will be to install babel
transpiler:
meteor npm install --save babel-runtime
这篇关于在Meteor.js应用程序中使用nodemailer运行批量电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!