How To Send E-Mails With BCC in Rails 3

23,534

Solution 1

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

Solution 2

on your user_mailer, on your mail def, add the following:

mail(:subject => "enter your subject", :bcc => "[email protected]")

you can also make your bcc recieve a list of emails

@bcc = User.all.pluck(:email)

then call

mail(:subject => "enter your subject", :bcc => @bcc)

hope this helps. :)

Solution 3

I've just exactly the same problem. It turns out in my case I was BCC'ing the same address I was TO'ing. ActionMailer or the mail server was doing something clever and choosing to only send one copy of the email.

I changed to using two different email addresses and BCC worked perfectly.

Solution 4

Check out http://railscasts.com/episodes/206-action-mailer-in-rails-3 and add 'default :bcc => "your_required_bcc_email" in your equivalent of the user_mailer.rb

Share:
23,534
silkwormy
Author by

silkwormy

Updated on April 13, 2020

Comments

  • silkwormy
    silkwormy about 4 years

    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