1

Rails ActionMailerを使用してAWS SESからメッセージIDを取得する方法:aws_sdkを配信方法として使用しますか?AWS SES with Rails ActionMailer

config.action_mailer.delivery_method = :aws_sdk 

私だけactionmailerので設定されたメッセージIDを取得していますが、それはSESによって上書きされます:

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

どうSESによって設定された実際のメッセージIDとSESからの応答を取得するには?私はこれを見つけたResponse from SMTP server with Rails、しかしそれは私のために働かなかった。

+0

は、私が使用してhttps://stackoverflow.com/questions/6374648/actionmailer-smtp-server-responseのように、 'ネット:: SMTP :: Response'を使用して応答を取得することができています:としてSMTP配送方法と '返信応答:true'を設定します。これは最もオプションの解決策ではありませんが。 – ZeroEnna

答えて

0

私はRubyの専門家ではありませんが、問題はAWSライブラリにあると思います。具体的には、return_response設定を設定する方法がないという事実があります。このファイルには

宝石/ 2.3.0 /宝石/ AWS-SDK-レール-1.0.1/libに/ AWS /レール/ mailer.rb

設定は、ハード、空のハッシュを返すようにコード化された機能です。そして、attr_accessorはなく、初期化もありません。そこ

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

そしてmessage.rbであなただけのdelivery_method.settings場合は、SMTP応答コードを取得することができます[:return_response]は真です。

# 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 

設定にアクセスできないため、応答を得る方法はありません。

awsライブラリの設定メソッドをオーバーライドするために、プリペンドのようなルビートリックを使用することは可能ですが、今はawsライブラリファイルにこの行を追加しています。

# ActionMailer expects this method to be present and to return a hash. 
    def settings 
    { :return_response => true } 
    end