Return-Path for ActionMailer
ByHaving spent several hours trying to get this to work, thought I’d share it with the world!
The Goal
When sending emails from an automated service like RSS:Forward it is common to want the return-path and the reply-to headers to be different.
This lets the receiver of the email reply to the author of the email while bounces are returned to another address which, presumably, updates the list database to ensure that bad email addresses are automatically removed from the list.
The Problem
Ruby on Rails does not support setting the return path when sending emails using ActionMailer
The Solution
- Use sendmail to deliver emails.
- Create your own
perform_delivery_sendmailmethod
The Details
Make sure that you configure ActionMailer to use sendmail by adding the following line to your config/environment.rb file.
config.action_mailer.delivery_method = :sendmail
Add to the top of your Mailer model so it looks like this…
class SubscriptionMailer < ActionMailer::Base def perform_delivery_sendmail(mail) IO.popen("/usr/sbin/sendmail -i -t -fno-reply@your.domain.com","w+") do |sm| sm.print(mail.encoded.gsub(/\r/, '')) sm.flush end end ...
The Fine Print
This will presumably not work on the MS legacy operating system.
Use the code at your own risk … it works for me
If you have a better solution, please let me know.









8 Comments
February 28th, 2009 at 1:26 pm
Hi nice post, i read your blog from time to time but i was wondering something. I also run a blog on a similar topic, but i get 1,000’s of spam comments and emails every day does that happen to you.. Any ideas to stop it? I currently have commenting disabled but i want to turn it back on.. Thanks!
March 3rd, 2009 at 6:41 pm
I rely on the Akismet plugin to protect from spam comments on all of my blogs. I don’t really know how many true comments are treated as spam, but I certainly don’t have much problem with managing spam which is transparently filtered by the plugin.
April 17th, 2009 at 10:34 am
I usually do not comment on blog posts but I found this quite interesting, so here goes. Thanks! Regards, P.
July 23rd, 2009 at 9:21 pm
I usually don’t post in blogs but your blog forced me to, amazing work.. beautiful !
August 18th, 2009 at 5:10 am
Yeah this cool I like this post are you going to do a follow up? I just won a Mac Book Air today
I am so happy about that found a freebee site http://budurl.com/MacBookAir
August 31st, 2009 at 6:11 am
Great blog you got here…keep up the good work.
August 31st, 2009 at 6:40 am
I really like this blog good job.
September 3rd, 2009 at 6:07 am
Your blog is so informative ?keep up the good work!!!!