Rails and Return-Path

How can I prevent Rails from stripping @header[‘Return-Path’] in an
outgoing e-mail? No matter what RFC says, there are some situations
where it is desirable to set an explicit Return Path, for instance to
handle bounces.

PeterB wrote:

How can I prevent Rails from stripping @header[‘Return-Path’] in an
outgoing e-mail?

I’ve been wondering the same. In our application we have a need to
place a generated hash into the return path for tracking purposes. I
have looked through the ActionMailer code, and it appears that TMail is
responsible for removing the return-path header field.

Can someone suggest a way to preserve the return-path that we have set?



I’ve looked further into this, and it is TMail which for some
inexplicable reason (overzealous compliance with RFC, possibly)
strips the Return-Path header from all outgoing mail. I’ll be writing
to the author for clarification as to the exact reasons for this kind
of Orwellian behaviour. Meanwhile, a work-around is to override the
following method in your Mailer subclass:

class Mailer < ActionMailer::Base

This performs delivery with an explicit FROM, using VERP. For

this to work,

the Rails mail delivery method has to be :sendmail. For :smtp to

work, you need

to specify address rewriting in the MTA (Postfix, Sendmail,

QMail, etc)

directly, since TMail doesn’t allow anyone to transfer a Return-


header, which is what we do here by using the -f option (VERP is


an added bonus).

def perform_delivery_sendmail(mail)
IO.popen("/usr/sbin/sendmail -itV+= -f [email protected]",“w
+”) do |sm|
sm.print(mail.encoded.gsub(/\r/, ‘’))

your mailer methods here


VERP is nice, and there is no reason you shouldn’t use it, as it
allows bounces of forwarded mail, etc. It also allows you to encode
the recipient’s address in the reply address, if you like, which may
be easier than having to decode the entire bounced email. If you
don’t want VERP, use the following string as the first parameter to
IO.popen instead:

"/usr/sbin/sendmail -i -t -f [email protected]"

It is curious that Rails uses an absolute path to Postfix’ sendmail
replacement, but it does.

Anyway, hope this is of some help.

/ Peter B.

26 sep 2006 kl. 07.37 skrev Cory Wright:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs