1

I am using Bert and Meteor Email. In my MEteor MEthods, I return the success of sending email. The problem is, after sending email, It does not return the success message.

here is my sample code,

Meteor.call('sendEmail',
                data.eadd,
                'e@gmail.com',
                'Invitation',
                'test');

            return "successful.";

Here is my sendEmail function,

sendEmail(to, from, subject, text) {
    check([to, from, subject, text], [String]);
    this.unblock();
    Email.send({
        to: to,
        from: from,
        subject: subject,
        text: text
    });
}
JMA
  • 844
  • 2
  • 11
  • 32
  • Possible duplicate of [How to get Meteor.Call to return value for template?](http://stackoverflow.com/questions/10677491/how-to-get-meteor-call-to-return-value-for-template) – rubie Dec 20 '16 at 09:44
  • Check out this question/answer - http://stackoverflow.com/questions/10677491/how-to-get-meteor-call-to-return-value-for-template - is that what you're looking for? – rubie Dec 20 '16 at 09:46

1 Answers1

1

Your Meteor.call() needs to include a callback and your sendEmail function needs to return a value. Rearrange your code as follows:

Meteor.call('sendEmail',data.eadd,'e@gmail.com','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.";  
}

Note: from a security pov I don't recommend such a method where the entire email can be specified on the client as you've basically created a scriptable open email relay - one that can even be run by an anonymous user.

Michel Floyd
  • 16,271
  • 4
  • 21
  • 38