node-sendmail icon indicating copy to clipboard operation
node-sendmail copied to clipboard

Feature request: pass the SMTP code on error

Open michael-ts opened this issue 7 years ago • 2 comments

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.

michael-ts avatar Nov 21 '17 19:11 michael-ts

@michael-ts what would you propose?

GreenPioneer avatar Dec 18 '17 04:12 GreenPioneer

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);

stormbard avatar Sep 11 '19 17:09 stormbard