[Ruby] ar_mailer including bcc headers
Victor Cosby
victorcosby at gmail.com
Mon Jul 30 03:56:46 PDT 2007
Thanks, Eric.
If I grab the destinations first within ARMailer, then set the TMail
object's bcc to nil, the message isn't created with the Bcc header but
all messages intended for Bcc recipients get created. If I nil out the
mail's bcc attribute before I deliver it, then of course they don't.
In other words:
def perform_delivery_activerecord(mail)
destinations = mail.destinations.dup
mail.bcc = nil
destinations.each do |destination|
@@email_class.create :mail => mail.encoded, :to => destination,
:from => mail.from.first
end
end
Do you think this is something I should submit as a patch to ar_mailer
or is there ever a case where ar_mailer would want to include a Bcc
header? Since mails sent this way expose the entire recipient list,
seems to defeat the purpose. I still haven't managed to track down how
ActiveMailer avoids sending the Bcc header but will keep poking.
As for using example.com for tests, I agree. That test method I
referred to is from ActionMailer's own test suite. :)
-Victor
On 7/29/07, Eric Hodel <drbrain at segment7.net> wrote:
> On Jul 29, 2007, at 14:04, Victor Cosby wrote:
>
> > I've been seeing Bcc headers in the messages I'm sending with
> > ar_mailer. This never happened in action_mailer so I'm trying to
> > determine why this might be different.
>
> I had never considered Bcc before.
>
> > The Bcc header is not sent in the deliveries sent via action_mailer,
> > and I believe I see a test for this in mail_service_test.rb (1.1.3):
> >
> > def test_headers_removed_on_smtp_delivery
> > ActionMailer::Base.delivery_method = :smtp
> > TestMailer.deliver_cc_bcc(@recipient)
> > assert MockSMTP.deliveries[0][2].include?("root at loudthinking.com")
> > assert MockSMTP.deliveries[0][2].include?
> > ("nobody at loudthinking.com")
> > assert MockSMTP.deliveries[0][2].include?(@recipient)
> > assert_match %r{^Cc: nobody at loudthinking.com},
> > MockSMTP.deliveries[0][0]
> > assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0]
> > assert_no_match %r{^Bcc: root at loudthinking.com},
> > MockSMTP.deliveries[0][0]
> > end
>
> You really, really, really need to use example.com for fake email
> addresses. That's what it is there for.
>
> > Since ARMailer creates a separate email message for each destination,
> > should it remove the Bcc header?
>
> Yes.
>
> > For example, this monkey patch is working for me, but I sense I might
> > be missing something.
> >
> > def perform_delivery_activerecord(mail)
> > # Remove Bcc header when creating the mail so recipients never
> > see it
> > mail.destinations.each do |destination|
> > @@email_class.create :mail => mail.encoded.sub(/^Bcc:.*\n/, ''),
> > :to => destination,
> > :from => mail.from.first
> > end
> > end
>
> You need to use the TMail methods to remove the Bcc header. If you
> have a bunch of Bcc addresses it'll be wrapped and you'll get your
> email thrown away due to invalid formatting.
>
> --
> Poor workers blame their tools. Good workers build better tools. The
> best workers get their tools to do the work for them. -- Syndicate Wars
>
>
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby
>
More information about the Ruby
mailing list