AWS SES对Rails ActionMailer的响应

问题描述 投票:1回答:1

当使用Rails ActionMailer:aws_sdk作为交付方法时,如何从AWS SES获取消息ID?

config.action_mailer.delivery_method = :aws_sdk

我只获取ActionMailer设置的message-id,但是被SES覆盖了:

response = ApplicationMailer.create_send(@message).deliver_now
puts response.message_id # => [email protected]

如何从SES获得SES设置的实际消息ID的响应?我找到了这个Response from SMTP server with Rails,但它对我不起作用。

ruby-on-rails amazon-web-services aws-sdk actionmailer amazon-ses
1个回答
0
投票

我不是ruby的专家,但我认为问题在于AWS库。具体而言,没有办法设置return_response设置。

在此文件中gems / 2.3.0 / gems / aws-sdk-rails-1.0.1 / lib / aws / rails / mailer.rb

settings是一个硬编码的函数,用于返回空哈希。并且没有attr_accessor,也没有初始化。

  # ActionMailer expects this method to be present and to return a hash.
  def settings
    {}
  end

在message.rb中,只有当delivery_method.settings [:return_response]为true时,才能获得smtp响应代码。

# 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

但由于无法访问设置,因此无法获得响应。

所以也许可以使用像prepend这样的ruby技巧来覆盖aws库中的settings方法,但是现在我只是将这行添加到aws库文件中。

  # ActionMailer expects this method to be present and to return a hash.
  def settings
    { :return_response => true }
  end
© www.soinside.com 2019 - 2024. All rights reserved.