email - reply - smtp headers




Set email headers so bounced emails go to a specific address (4)

From our rails app we send out some system-generated emails with the 'from' address set to [email protected] If these bounce they get sent back to this address by our mail server. However, what i'd like to do is to not have bounced emails get sent back to [email protected] but to a different address, such as [email protected]

Is there a header or something i can set in the email that will achieve this, without me having to go and investigate the vagaries of our email server? We send the mails out using exim in case that's relevant.

cheers, max


3 years too late, but just in case anyone else comes this way. Return-Path is the right header but, as James Garriss pointed out above, it has to be placed there by the site performing final delivery. You can't just stick it in yourself.

If you're writing emails by connecting directly to an SMTP server then this is easy - the MAIL command contains the return path. If you send

MAIL FROM:<[email protected]>

to the SMTP server then bounces will be returned to [email protected].

If you're not constructing SMTP, and you're running an MTA (ie. exim/etc), then you have to find a command-line switch for your MTA. For sendmail, -f [email protected] "sets the sender's address", and this ends up as the Return-Path in the final delivered mail, and [email protected] will get the bounces (I do exactly this for auto-generated emails). I haven't tried this on exim, but it has exactly the same option, and it should work.


Return-Path header is written by the receiving server, not by the sending server. And as per the RFC 5321, it is the same as the address supplied in MAIL FROM command.

Even if you set the Return-Path header yourself, the receiving server will overwrite that.

Now, here's the thing, the address in the MAIL FROM command and the address in the From header can be different. The receiving user does not see the MAIL FROM address. They only see the From header address.

So, if you want to ignore the bounces or want them to go to a specific address, you should use that address in the MAIL FROM command.

But in the From header, you can just use [email protected] - the user will see this address.


To simplify a bit more, you send the email from [email protected] address. The receiving server will send the bounces to this address.

To show your user the [email protected] address instead of handle_bounce... address, set the From header in the raw email MIME message to the noreply... address.


I recently got a no-reply email from Bitbucket. Here's the raw message:

Return-Path: <[email protected]r.atlassian.com>
From: "Atlassian Bitbucket" <[email protected]>
To: <[email protected]>
Subject: Continuous delivery, without the headache.
Date: Wed, 28 Feb 2018 12:40:53 -0600
MIME-Version: 1.0
Reply-To: "Atlassian Bitbucket" <[email protected]mailer.atlassian.com>

... message body ...

As you can see, the Return-Path is an address dedicated to handle bounces. But the From address is a [email protected] mail. What that means is this email was actually sent by this bounce handling address, not by the noreply address.

You can also see the Reply-To header, which is dedicated to handle replies, if a user replies to no-reply emails. Those replies are probably discarded right away.



I just figured this out myself in exim4 after a lot of reading about exim configuration.

First, you want your app to add the following header:

Return-Path: <[email protected]>

Works with or without brackets. Exim will add brackets in the end either way.

Second, this was the hard part. Exim always wanted to override my Return-Path: address with the unix user who sent it. You can use /etc/email-addresses in Ubuntu to set a static email for the user of your web app, but this still ignores the Return-Path header. Here is how I modified my exim config to respect the Return-Path from the web app:

In the main config area add:

return_path_remove = false

In the appropriate router config (e.g. dnslookup):

dnslookup:
  # ...
  errors_to = ${if def:h_return-path: {${address:$h_return-path:}} fail}
  headers_remove = return-path
  no_more

Now exim should copy the Return-Path header address at the envelope-level and delete the original Return-Path header.

I tried lots of other configuration directives and this is the only way that actually worked for me.





exim