开发者

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@email.com" 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 => "my@email.com",
       :subject => "Congratulations, #{booking.contact_name}!")
end

also tried:

def booking_confirmed_email(booking)
  @booking = booking
  mail(:to => booking.contact_email,
       :bcc => ["my@email.com"],
       :subject => "Congratulations, #{booking.contact_name}!")
end
开发者_JAVA技巧

to no avail


Full details here:

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

Short answer:

mail(:to => "some@example.com" ,  :subject => "Example Subject",
     :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"] ,
     :cc => "other@example.com" )

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


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.


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

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

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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜