guileen / node-sendmail

send mail without setting up a SMTP server
http://guileen.github.com/node-sendmail
MIT License
559 stars 110 forks source link

Feature request: pass the SMTP code on error #43

Open michael-ts opened 6 years ago

michael-ts commented 6 years ago

My understanding is that if I call sendmail() and there is a 4XX error code, it is transient and I should retry the call after some delay.

But there is no easy and foolproof way to determine if this is the case.

In sendmail.js:216 I see my callback called as follows:

callback(new Error('SMTP code:' + code + ' msg:' + msg));

This is inconvenient because to determine if there was a 4xx error I have to do some kind of parsing on the string such as via a regex. I can do this, but it is concerning to me because given the total lack of documentation on what the format of the callback parameters are supposed to be, it is conceivable that at some point somebody will decide to reformat the message somehow, breaking my code.

GreenPioneer commented 6 years ago

@michael-ts what would you propose?

stormbard commented 5 years ago

Maybe something like this? This would be a nice to have so that you can better handle the errors on the consumer side.

callback(new Error(
{
   smtpCode: code, 
   smtpResponse: msg, 
   message: 'SMTP code:' + code + ' msg:' + msg"
}));

Or this might be better.

let err = new Error('SMTP code:' + code + ' msg:' + msg);
err.smtpCode = code;
err.smtpResponse = msg;
callback(err);