How do I get message-id from AWS SES when using Rails ActionMailer with :aws_sdk as a delivery method?
config.action_mailer.delivery_method = :aws_sdk
I am only getting the message-id set by ActionMailer, but that gets overwritten by SES:
response = ApplicationMailer.create_send(@message).deliver_now
puts response.message_id # => [email protected]
How to get the response from SES with actual message-id set by SES? I found this Response from SMTP server with Rails, but it didn't work for me.
I'm not an expert in ruby but I think the problem is with the AWS library. Specifically with the fact that there is no way to set the return_response setting.
In this file gems/2.3.0/gems/aws-sdk-rails-1.0.1/lib/aws/rails/mailer.rb
settings is a function hard coded to return an empty hash. And there is no attr_accessor and there is no initialize for it either.
# ActionMailer expects this method to be present and to return a hash.
def settings
{}
end
And in message.rb there you can get the smtp response code only if delivery_method.settings[:return_response] is true.
# This method bypasses checking perform_deliveries and raise_delivery_errors,
# so use with caution.
#
# It still however fires off the interceptors and calls the observers callbacks if they are defined.
#
# Returns self
def deliver!
inform_interceptors
response = delivery_method.deliver!(self)
inform_observers
delivery_method.settings[:return_response] ? response : self
end
But because settings is not accessible, there is no way to get the response.
So maybe it is possible to use a ruby trick like prepend to override the settings method in the aws library, but for now I'm just adding this line to the aws library file.
# ActionMailer expects this method to be present and to return a hash.
def settings
{ :return_response => true }
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With