silkwormy
silkwormy

Reputation: 677

How To Send E-Mails With BCC in Rails 3

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

Upvotes: 31

Views: 26210

Answers (5)

Alexander Gorg
Alexander Gorg

Reputation: 1078

If you are using any queue adaptor (ex. Sidekiq) - try restart it.

Upvotes: 0

Tilo
Tilo

Reputation: 33732

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

Upvotes: 56

Rennan Oliveira
Rennan Oliveira

Reputation: 96

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. :)

Upvotes: 4

Adam Pope
Adam Pope

Reputation: 3274

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.

Upvotes: 4

Rutger
Rutger

Reputation: 185

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

Upvotes: 2

Related Questions