2

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 # => 5a1fbd6417a83_12a406a883740@28b9af04e9b9.mail

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.

ZeroEnna
  • 43
  • 3
  • I am able to get the response using `Net::SMTP::Response`, like in https://stackoverflow.com/questions/6374648/actionmailer-smtp-server-response by using :smtp as a delivery method and setting `return response: true`. Though this is not the most optional solution. – ZeroEnna Nov 30 '17 at 10:59

1 Answers1

0

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
Zachary Spath
  • 51
  • 1
  • 2