[Ruby] ar_mailer including bcc headers

Eric Hodel drbrain at segment7.net
Sun Jul 29 20:34:51 PDT 2007


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




More information about the Ruby mailing list