How To Send E-Mails With BCC in Rails 3

silkwormy picture silkwormy · Jul 4, 2011 · Viewed 21.9k times · Source

How can I send e-mails with the BCC header? I follow the ruby on rails guide and set :bcc => "[email protected]" and it doesn't work.

Thanks

edit by corroded Here's the code I tried:

def booking_confirmed_email(booking)
  @booking = booking
  mail(:to => booking.contact_email,
       :bcc => "[email protected]",
       :subject => "Congratulations, #{booking.contact_name}!")
end

also tried:

def booking_confirmed_email(booking)
  @booking = booking
  mail(:to => booking.contact_email,
       :bcc => ["[email protected]"],
       :subject => "Congratulations, #{booking.contact_name}!")
end

to no avail

Answer

Tilo picture Tilo · Oct 25, 2011

Full details here:

http://api.rubyonrails.org/classes/ActionMailer/Base.html

Short answer:

mail(:to => "[email protected]" ,  :subject => "Example Subject",
     :bcc => ["[email protected]", "Order Watcher <[email protected]>"] ,
     :cc => "[email protected]" )

note how you can pass an array of email addresses to each of the :to, :cc, :bcc options.

RailsCast:

http://railscasts.com/episodes/206-action-mailer-in-rails-3