LoginSignup
6
5

More than 5 years have passed since last update.

RAILS_ENV=production で ActionMailer の BCC 送信が機能してない

Posted at

Development では送信できているのに。なんででしょうか?

わかりました。Production のメール送信は Amazon SES を使ってたのが原因ぽい。

Amazon SES は BCC が苦手らしい

エンタープライズ用途に SES は使えない、とまで書いてある。

aws-ses.gem の GitHub Issue にも書いてあった。

AWS::SES::SendEmail.class_eval do
  #TN: made bbc work with ses
  def send_raw_email(mail, args = {})
    message = mail.is_a?(Hash) ? Mail.new(mail).to_s : mail.to_s
    package = { 'RawMessage.Data' => Base64::encode64(message) }
    package['Source'] = args[:from] if args[:from]
    package['Source'] = args[:source] if args[:source]

    # Extract the list of recipients based on arguments or mail headers
    destinations = []
    if args[:destinations]
      destinations.concat args[:destinations].to_a
    elsif args[:to]
      destinations.concat args[:to].to_a
    else
      destinations.concat mail.to.to_a
      destinations.concat mail.cc.to_a
      destinations.concat mail.bcc.to_a
    end
    add_array_to_hash!(package, 'Destinations', destinations) if destinations.length > 0

    request('SendRawEmail', package)
  end

  alias :deliver! :send_raw_email
  alias :deliver  :send_raw_email

end
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5