From our rails app we send out some system-generated emails with the 'from' address set to noreply@ourdomain.com. 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 noreply@ourdomain.com but to a different address, such as bounced@ourdomain.com.
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
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:
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:
In the appropriate router config (e.g. dnslookup):
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.
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 sendto the SMTP server then bounces will be returned to
me@foo.com
.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 me@foo.com
"sets the sender's address", and this ends up as theReturn-Path
in the final delivered mail, andme@foo.com
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.Errors-To is deprecated, so mail servers will typically ignore this header - most servers will bounce will to the 'envelope sender'.
This is the email address that your mail client sends as part of the connection to the SMTP server (not necessarily the From address - though it typically is the same).
I don't know Rails all that well, but I found this - although, as far as I can tell Return-Path is reset by MTAs to match the MAIL FROM information from the client, so it seems you can't actually set it.
I think the only thing you can do is set the bounce address in your server.
Here is the solution:
In the email header you can set:
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 inMAIL 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 theFrom
header can be different. The receiving user does not see theMAIL FROM
address. They only see theFrom
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 usenoreply@yourdomain.com
- the user will see this address.To simplify a bit more, you send the email from
handle_bounce@yourdomain.com
address. The receiving server will send the bounces to this address.To show your user the
noreply@yourdomain.com
address instead ofhandle_bounce...
address, set theFrom
header in the raw email MIME message to thenoreply...
address.I recently got a no-reply email from Bitbucket. Here's the raw message:
As you can see, the
Return-Path
is an address dedicated to handle bounces. But theFrom
address is anoreply@...
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.