nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
862 stars 146 forks source link

How to customize response envelope #129

Closed niftylettuce closed 5 years ago

niftylettuce commented 5 years ago

In ForwardEmail.net - I'd like to map the responses from the email server I'm forwarding to back to the original RCPT. For example, hello@nodemailer.com gets forwarded to a@gmail.com and b@gmail.com, and test@nodemailer.com gets forwarded to c@gmail.com. If A and B are successful, but C is not, I do not want all (3) to fail. I still want the client to know that C is not successful, and for a particular reason. Is there a way to customize the callback second argument in onData(stream, session, callback) such that we could do something like callback(null, { accepted: [ ... ], rejected: [ ... ], rejectedErrors: [ ... ] })?

andris9 commented 5 years ago

Not with SMTP, this is only possible with LMTP where you get a separate DATA response for each RCPT. With SMTP all recipients fail or succeed at once. The correct way to handle this is to accept the messages, and then generate bounce emails for failed recipients.

niftylettuce commented 5 years ago

Brilliant

andris9 commented 5 years ago

For generating bounces you should use a checklist:

You can check out an example for generating a bounce message from zone-mta bounce handler

niftylettuce commented 4 years ago

@andris9 thanks for this - following up here, I think that your statement here is inaccurate:

No bounces for messages with Auto-Submitted or X-Auto-Response-Suppress headers

Instead, I think we should check the following:

Ref: https://www.jitbit.com/maxblog/18-detecting-outlook-autoreplyout-of-office-emails-and-x-auto-response-suppress-header/

niftylettuce commented 4 years ago

@andris9 Just a follow up - your Zone MTA code would result in the following bounce in Gmail:

Screen Shot 2020-05-17 at 5 16 19 AM

I've fixed it on my side, and now it looks like this:

Screen Shot 2020-05-17 at 7 15 56 AM

If you're curious how I fixed it, see this: https://github.com/forwardemail/free-email-forwarding/blob/cb2a2e3b6bc47740a90b2a110d868dab723cb840/index.js#L416-L511