Skip to content
This repository

Bcc doesn't work through rails 3 #16

Open
codev opened this Issue April 23, 2011 · 25 comments
Marc Sutton
codev commented April 23, 2011

I'm trying to deliver mail through Rails 3 Action Mailer with:

mail :to => "address@domain.com",
      :bcc => ['one@domain.com', 'two@domain.com'],
      :subject => 'Blah'

The mail only gets sent to the :to address, the :bcc list is ignored. I believe the destinations are being reconstructed by Amazon as send_raw_email in lib/aws/ses/send_email.rb doesn't extract anything from the Mail object apart from the encoded message. It need something like this (but better, I just wrote this here and haven't tested it) to replace the current destinations code:

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
Marc Sutton codev referenced this issue from a commit in codev/aws-ses May 02, 2011
Marc Sutton Add support for BCCing from rails (based on the mail object). Fixes #16
… on drewblas/aws-ses.
4b087df
i7a
i7a commented May 11, 2011

Hi.

It's gonna be a great help for me if I could know whether this issue happens with rails2 or not. Do you have any information about it?

Since I'm not using aws-ses from rails and facing this issue, I want to know if downgrading some gems wil help.

Marc Sutton
codev commented May 11, 2011

I'm haven't tested with rails 2 so I don't know I'm afraid. It uses a slightly different code path so might be ok.

i7a
i7a commented May 11, 2011

OK,I see. Thanks anyway.

If I could take a time I'll try it by myself.

TinNT commented May 26, 2011

thank you!

my workaround: override the send_raw_email method the initializers

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
pixelterra

Is this issue resolved? I'm having the same issue...

pixelterra

I'm use TinNT's monkey patch for now. Thanks!

curtp

I tried using TinNT's monkey patch, but when the emails are delivered, the addresses sent in the Destinations are visible in the TO field. I added logging and verified the TO fields aren't populated in the raw message and only appear as part of the Destinations section of the package.

Any ideas?

pixelterra

@curtp

I think this happens to me as well. I'm not sure how the ses api works. It might not support this feature. For now, I'm just looping through each recipient and sending individual mails out. Good luck.

curtp

I found this post on the AWS SES forum which describes this. Supposedly they fixed it in the service.

https://forums.aws.amazon.com/thread.jspa?messageID=277021&#277021

curtp

@pixelterra

Ugh.... that will test the sending limits on our app. We really need the BCC capability.

Mark Nadig

+1 just discovered this bug today as well

Khurram Virani

Just took a quick glance at the AWS SES docs...

It appears that the sendRawEmail API endpoint doesn't support BCC but the sendEmail one does. Is this true? Anyone notice this as well or am I just reading the docs incorrectly?

John Eberly

+1 here too... discovered and had to roll back to old provider....

Aditya Sanghi

+1 I think this is fairly important. Can we make this work or should we shelve SES decision until later? BCC is very important to us in our current project.

Joshua Pinter

+1 from me as well.

Kenn Ejima

Turns out, the official aws-sdk supports bcc. Setup was as simple as this gem, FYI.

http://docs.amazonwebservices.com/AWSRubySDK/latest/AWS/SimpleEmailService.html

Thanks @drewblas for helping us to this date, though!

Constantine Nicolaou

I'm facing the same issue as well. The monkey patch seems to be working fine, so thank you @TinNT

Is it possible to have the pull request applied?

Brian Armstrong

Like @kenn mentioned - ended up moving to the aws-sdk gem. Fixed the issue.

Quick port:

# Gemfile
# gem "aws-ses", "~> 0.4.4", :require => 'aws/ses' 
gem 'aws-sdk',                       '1.7.0'

# initializer
# ActionMailer::Base.add_delivery_method :ses, AWS::SES::Base, {access_key_id: ENV['SES_ACCESS_KEY_ID'], secret_access_key: ENV['SES_SECRET_ACCESS_KEY']}
AWS.config(access_key_id: ENV['SES_ACCESS_KEY_ID'], secret_access_key: ENV['SES_SECRET_ACCESS_KEY'])

# production.rb
# config.action_mailer.delivery_method = :ses
config.action_mailer.delivery_method = :amazon_ses

# Want to test in dev first?  add to development.rb
config.action_mailer.delivery_method = :amazon_ses
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true

Ship it. Hope it helps.

Caleb Brown

Thanks @barmstrong. I just used your comment and I'm bcc'ing.

Wayne

This gem still doesn't support BCCing? I just tried today with ruby 1.9.3 and Rails 3.2.13 and it didn't work.

Drew Blas
Owner

This gem uses what is essentially the exact same code for send_raw_email as the aws-sdk gem for handling destinations:

https://github.com/drewblas/aws-ses/blob/master/lib/aws/ses/send_email.rb#L98

https://github.com/aws/aws-sdk-ruby/blob/master/lib/aws/simple_email_service.rb#L333

Some people have reported it working while others have said one works and the other doesn't. Unfortunately, I haven't yet gotten a detailed enough error report to be able to find the root cause. If anyone can capture the API call that both gems are making and show what the difference is that is causing BCC not to work, I'd be happy to make an adjustment.

Shehbaz

The gem still does not support BCC. Tried with ruby 1.9.3 p392 and Rails 3.2.12.

Shehbaz

I have used @barmstrong solution. aws-sdk works perfectly.

Ryan Detert

I was having the same problem still in Rails 3.2.16 using Ruby 1.9.3. Using @barmstrong solution worked

Tatsuro Baba tbaba referenced this issue from a commit in grooves/aws-ses May 02, 2011
Marc Sutton Add support for BCCing from rails (based on the mail object). Fixes #16
… on drewblas/aws-ses.

Conflicts:
	lib/aws/ses/send_email.rb
d7b2b50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.