guileen / node-sendmail

send mail without setting up a SMTP server

Home Page:http://guileen.github.com/node-sendmail

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: pass the SMTP code on error

michael-ts opened this issue · 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 what would you propose?

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