orliesaurus / nodemailer-mailgun-transport

nodemailer is an amazing node module to send emails within any of your nodejs apps. This is the transport plugin that goes with nodemailer to send email using Mailgun 🔫
MIT License
882 stars 98 forks source link

Unhandled rejection Error: 'to' parameter #74

Closed fabioel closed 4 years ago

fabioel commented 6 years ago

Hello! I have stumbled across a problem that I can't fix. I am trying to send emails to a list of receivers, but the emails should contain individual properties, therefore I cannot just send a bulk email with an array of receivers. My code looks as follows: in my method call:

 _.forEach(data, function (user) {
   mailPromise = mail.sendTemplateMail(user.email, 'Status', '', user, type);
   mailPromises.push(mailPromise);
});
Promise.all(mailPromises).then(function (res) {
//do some error checking
});

the mail file:

function sendTemplateMail(recv, subj, text, data, type) {
    var context = {
        text: text,
        data: data || {},
    };
    return transporter.sendMail({
        from: admin,
        to: recv,
        subject: subj,
        template: {
            name: templates[type],
            engine: 'handlebars',
            context: context
        }
    });
}

This code has worked perfectly fine when I was using nodemailer-transport with gmail, but now I receive the following error, when an email address is not valid:

Unhandled rejection Error: 'to' parameter is not a valid address. please check documentation
    at IncomingMessage.<anonymous> (/home/fabio/node_modules/nodemailer-mailgun-transport/node_modules/mailgun-js/lib/request.js:301:15)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

What I would like to have is that I can use Promise.all to check if all the email promises were done properly. Why is there error thrown an interrupts my procedures?

framp commented 5 years ago

This is not a bug in the library and this issue can be closed /cc @orliesaurus

@fabioel: Error: 'to' parameter is not a valid address One of the recv you're sending must not be a valid address

Can you please print recv and see what kind of address is throwing an error?