Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set email headers so bounced emails go to a specific address

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

like image 737
Max Williams Avatar asked Mar 14 '11 19:03

Max Williams


People also ask

Where does a bounced email return to?

There are many different possibilities for an email bouncing. As a result, a "return to sender" message (also known as an SMTP Reply) is applied and sent from the recipient's mail server with a more detailed explanation for the bounce back. It's an annoying occurrence in email delivery.

How do I filter a bounced email in Gmail?

Use the Gmail search tool to search for “from:[email protected]”, and then search. This will show all of the bounce notifications you've received. 2. Next, click the GMass “Build Email List” button.


1 Answers

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.

like image 75
ColinM Avatar answered Sep 19 '22 07:09

ColinM