我试图在服务器端方法中使用Meteor.Mandrill.send函数。
我希望mandrill方法是同步的,所以我尝试了这个:
sendActivationCode: function(liftId, email) {
check(liftId, String);
check(email, String);
var body = 'hello';
wrappedMandrillSend = Meteor.wrapAsync(Meteor.Mandrill.send, Meteor.Mandrill);
var sentMail = wrappedMandrillSend({
host: "smtp.mandrillapp.com",
port: 587,
to: email,
from: "info@website.meteor.com",
subject: 'Activation mail',
html: body,
authentication: "LOGIN",
username: Meteor.settings.mandrill.username,
password: Meteor.settings.mandrill.password
});
console.log('sync mail send');
return sentMail;
}
但是永远不会显示sync mail send
。并且函数永远不会返回。
感谢您的帮助。
答案 0 :(得分:0)
如果您正在使用此程序包:https://atmospherejs.com/wylio/mandrill(wylio:mandrill
),则无需使用wrapAync。只需正常使用它:
sendActivationCode: function(liftId, email) {
check(liftId, String);
check(email, String);
var body = 'hello';
var sentMail = Meteor.Mandrill.send({
host: "smtp.mandrillapp.com",
port: 587,
to: email,
from: "info@website.meteor.com",
subject: 'Activation mail',
html: body,
authentication: "LOGIN",
username: Meteor.settings.mandrill.username,
password: Meteor.settings.mandrill.password
});
console.log('sync mail send');
return sentMail;
}
它不起作用的原因是它试图使已经同步的方法再次同步。它没有回调因此它不会返回。