简体   繁体   English

如何在 Rails 3 中使用密件抄送发送电子邮件

[英]How To Send E-Mails With BCC in Rails 3

How can I send e-mails with the BCC header?如何使用密件抄送 header 发送电子邮件? I follow the ruby on rails guide and set :bcc => "email@email.com" and it doesn't work.我遵循 Rails 指南上的 ruby 并设置:bcc => "email@email.com"但它不起作用。

Thanks谢谢

edit by corroded Here's the code I tried:由 corroded 编辑这是我尝试过的代码:

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

to no avail无济于事

Full details here:完整的细节在这里:

http://api.rubyonrails.org/classes/ActionMailer/Base.html 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.请注意如何将 email 地址数组传递给每个:to、:cc、:bcc 选项。

RailsCast: RailsCast:

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

on your user_mailer, on your mail def, add the following:在您的 user_mailer 上,在您的邮件定义上,添加以下内容:

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.希望这可以帮助。 :) :)

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. ActionMailer 或邮件服务器做了一些聪明的事情,并选择只发送一份 email 的副本。

I changed to using two different email addresses and BCC worked perfectly.我改为使用两个不同的 email 地址,BCC 运行良好。

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查看http://railscasts.com/episodes/206-action-mailer-in-rails-3并在相当于 user_mailer.rb 中添加 'default:bcc => "your_required_bcc_email"

If you are using any queue adaptor (ex. Sidekiq) - try restart it.如果您正在使用任何队列适配器(例如 Sidekiq) - 请尝试重新启动它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM