从Rails的SMTP服务器响应(Response from SMTP server with Ra

2019-10-19 23:49发布

我怎么能得到在Ruby中使用的ActionMailer,Rails的SMTP服务器的响应时,我发送一封电子邮件与Mailer.deliver方法?

我发现的ActionMailer SMTP服务器响应的答案,但它不工作...任何想法?

我需要它,因为AWS SES返回消息ID通过,这是获得链接到他们后提供一个反弹或垃圾邮件报告消息的唯一途径。

Answer 1:

如果你的SMTP像这样

response = Mail.your_mail().deliver

并没有得到响应,你需要尝试deliver_now!

response = Mail.your_mail().deliver_now!
pp response.message

这将显示你的结果是:250 2.0.0确定:排队的3lG8S16Khmz6ZhXq

我也对我的Mail.rb配置SMTP设置

delivery_options = {   user_name: 'email@server.com.br',
                       password: 'mypassword',
                       authentication: :login,
                       address: 'smtp.mycompany.com.br',
                       port: 2525,
                       domain: 'mycompany.com.br',
                       return_response: true
                    }


Answer 2:

如果使用宝石“AWS-SES”你可以得到消息ID用:

response = your_mailer.send(notification, self, *args).deliver_now!
response.message_id # => "010601531c886c55-6c2f30fc-4237-4294-9029-b60b2d44a691-000000@email.amazonses.com"

对于我deliverdeliver_nowdeliver_now! 以同样的方式工作

EXTRA:如果由于某种机会,你使用的是设计,你可以得到的ID太:

#[app/model/user.rb]
class User < ActiveRecord::Base
  ...
  # Override send_devise_notification stated in devise/REAMDE.txt
  def send_devise_notification(notification, *args)                      
    response = devise_mailer.send(notification, self, *args).deliver_now
    response.message_id #=> "010601531c8-86c...000000@email.amazonses.com"
  end
  ...
end


文章来源: Response from SMTP server with Rails