8

nodemailer : "^2.4.2"

I am sending mail using nodemailer. It's working fine. But while using not existing email, I am not getting any error:

I have code as;

exports.sendMail = function (req, resp, reqBody, callback) {
    var smtpTransport = nodemailer.createTransport(settings.smtpConfig);
    var data = JSON.parse(reqBody);
    var mailOptions={
        to      : data.toAddress,
        cc      : data.ccAddress,
        bcc     : data.bccAddress,
        subject : data.subject,
        html    : data.message
    }
    smtpTransport.sendMail(mailOptions, function(error, response){
        if (error) {
            callback(null, error);
        }else{
            callback(response);
        }
    });
};

So if i use any not existing email Id it doesn't throw any error;

For eg:If I send toAddress as 'dummy@gmail.com' -- it doesn't throw any error.

I got response as

{ accepted: [ 'dummy@gmail.com' ],
  rejected: [],
  response: '250 2.0.0 OK 1466501212 23sm18003603qty.40 - gsmtp',
  envelope: { from: '', to: [ 'dummy@gmail.com' ] },
  messageId: '1466501201867-84b63b27-ce337819-b06c739f@localhost' }

Same case for cc also.

Any help appreciated.

Sawan Kumar
  • 327
  • 1
  • 5
  • 13
  • It is correct. nodemailer just passes the message to the relay. This relay doesn't know at this point that the given address is incorrect. If the last SMTP server in the chain is not able to deliver the message it will be bounced back to the sender (in this case the relay nodemailer passed the message to) but not to nodemailer. Thats just how SMTP works. – KRONWALLED Jun 21 '16 at 09:40
  • @KRONWALLED : Thanks for your response. So there is no way, we can catch bounce emails. – Sawan Kumar Jun 21 '16 at 09:56
  • I looked around a little bit. Out of the box no but [here](https://github.com/nodemailer/nodemailer/issues/487) you can see an example how you could setup your system – KRONWALLED Jun 21 '16 at 10:01
  • 1
    @KRONWALLED : I used envelope: { from: 'emailAddress', to: toAdd } I am able to check bounce mail in mails. But cc does't work in this case. If I remove envelope then its work perfectly. – Sawan Kumar Jun 23 '16 at 09:01

0 Answers0