Altering e-mail ‘Return-Path’ with exim4 and PHP mailer in Wikitech Labs

While implementing VERP, I always found that the ‘Return-Path’ address of any send email — was getting rewritten to root@wikimedia.org. This was frustrating as I had already changed the $header['Return-Path'] many times in the UserMailer.php and the result was just this one.
Problem:-
* Rewrite custom generated Return-Path to email-headers while sending
* Implement VERP addressing to handle bounces
Solution:-
*The PHP part:
+ Make sure the UserMailer.php ( or anyother file that sends the mail ) have custom header configurations such as:

$headers[ ‘Return-Path’ ] = ‘return-to-here@domain’ ;
mail( $to, $sub, $body, $headers );
*Now, the exim4 part:
+ Open your sudo nano /etc/exim4/exim4.conf and add the following line to the main configuration area:
( optional )

# Return Path
return_path_remove = false 

+ Remove the line errors_to from the desired router (( here wiki_mail router )

wiki_mail:
driver = manualroute
condition = ${if eqi{$header_X-Mailer:}{MediaWiki mailer}}
errors_to = ${if def:h_return-path: {${address:$h_return-path:}} fail}
headers_remove = return-path
transport = remote_smtp
route_list = *     

Yay! all done. Now, $ sudo /etc/init.d/exim4 restart
Now test it by sending a mail to some remote id, using Special:EmailUser
PS: There is a shorter version, with just removing the errors_to from the wiki_mail router.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s