2016-12-20 88 views
1

我正在使用Bert和流星电子邮件。在我的流星ME中,我返回发送电子邮件的成功。问题是,在发送电子邮件后,它不会返回成功消息。流星电子邮件成功提醒

这里是我的示例代码,

Meteor.call('sendEmail', 
       data.eadd, 
       '[email protected]', 
       'Invitation', 
       'test'); 

      return "successful."; 

这里是我的sendEmail功能,

sendEmail(to, from, subject, text) { 
    check([to, from, subject, text], [String]); 
    this.unblock(); 
    Email.send({ 
     to: to, 
     from: from, 
     subject: subject, 
     text: text 
    }); 
} 
+0

[如何让Meteor.Call返回模板的值?](http://stackoverflow.com/questions/10677491/how-to-get-meteor-call-to-return-value-for - 模板) – rubie

+0

看看这个问题/答案 - http://stackoverflow.com/questions/10677491/how-to-get-meteor-call-to-return-value-for-template - 是你在找什么对于? – rubie

回答

1

Meteor.call()需要包括回调和你sendEmail函数需要返回一个值。重新安排你的代码如下:

Meteor.call('sendEmail',data.eadd,'[email protected]','Invitation','test',(err,result)=>{ 
    if (err) Bert.alert({ title: 'Error sending email: '+err, type: 'danger' }); 
    else Bert.alert({ title: 'Email sent!', type: 'success' }) 
}); 

sendEmail(to, from, subject, text) { 
    check([to, from, subject, text], [String]); 
    this.unblock(); 
    Email.send({ 
    to: to, 
    from: from, 
    subject: subject, 
    text: text 
    }); 
    return "successful."; 
} 

注:从安全POV我不建议这样在整个电子邮件可以在客户端,你已经基本上创建一个脚本打开电子邮件继电器指定的方法 - 甚至可以由匿名用户运行。