Know when Email.send() is Completed or failed

Hey All,

I’m trying to send 100 emails as fast as possible. Following is my code

let sendEmail = function(emails, content) {
        Meteor.setTimeout(Meteor.bindEnvironment(()=>{
            let to = 'myemail@somewhercom';
            try {
                Email.send({
                    to: to,
                    from: 'info@mydomain.com',
                    subject: 'Testing here',
                    html: '<h1>Hello</h1>'
                });
            } catch(e) {
                console.log(e, to);
            }
        })
      );
    };

And from my server method is as follows

campaign.sendEmails': function(campaignId, subscribers) {
            check(campaignId, String);
            check(subscribers, Array);

            this.unblock();
            
            for (var i = 100 - 1; i >= 0; i--) {
                console.log('hello, ', i);
                try {
                    sendEmail();
                } catch (e) {
                    return e;
                }
            }
        }

This is only testing code

I have no way to see if the Email.send has completed or not ?!?

Any thoughts guys ?

1 Like

The actual process of sending the email is not handled by Meteor / Node but by something like sendmail.

Thus, to determine whether you successfully sent an e-mail, you’d have to parse the logs in /var/log/.

Which, by the way, you shouldn’t bother with. Make sure that you can send emails and that your server is correctly configured so that they can arrive in a user’s inbox (and not in the spam folder). And that’s it.

Try removing the Meteor.bindEnvironment bit and see if it still works. Meteor.setTimeout should automatically give you a Meteor environment.