aws-ses
aws-ses copied to clipboard
Bcc doesn't work through rails 3
I'm trying to deliver mail through Rails 3 Action Mailer with:
mail :to => "[email protected]",
:bcc => ['[email protected]', '[email protected]'],
: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
https://github.com/codev/aws-ses/commit/4b087dfa34b38b819b01d673518b5fcad2a9fbeb
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.
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.
OK,I see. Thanks anyway.
If I could take a time I'll try it by myself.
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
Is this issue resolved? I'm having the same issue...
I'm use TinNT's monkey patch for now. Thanks!
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?
@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.
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񃨝
@pixelterra
Ugh.... that will test the sending limits on our app. We really need the BCC capability.
+1 just discovered this bug today as well
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?
+1 here too... discovered and had to roll back to old provider....
+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.
+1 from me as well.
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!
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?
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.
Thanks @barmstrong. I just used your comment and I'm bcc'ing.
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.
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.
The gem still does not support BCC. Tried with ruby 1.9.3 p392 and Rails 3.2.12.
I have used @barmstrong solution. aws-sdk works perfectly.
I was having the same problem still in Rails 3.2.16 using Ruby 1.9.3. Using @barmstrong solution worked
thanks @barmstrong :thumbsup: