问题
How could I get the response from an SMTP server in Ruby on Rails using ActionMailer, when I send an email with the Mailer.deliver
method?
I found the Actionmailer SMTP Server Response answer but it doesn't work... Any idea?
I need it because AWS SES return a message ID through, and it's the only way to get the message linked to a bounce or spam report they provide after.
回答1:
if you get the smtp in way like this
response = Mail.your_mail().deliver
and it isn't getting the response that you need, try deliver_now!
response = Mail.your_mail().deliver_now!
pp response.message
This will show you the result: 250 2.0.0 Ok: queued as 3lG8S16Khmz6ZhXq
I also configured the smtp settings on my Mail.rb
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
}
回答2:
If using gem "aws-ses" you can get the message id with:
response = your_mailer.send(notification, self, *args).deliver_now!
response.message_id # => "010601531c886c55-6c2f30fc-4237-4294-9029-b60b2d44a691-000000@email.amazonses.com"
For me deliver
, deliver_now
and deliver_now!
work in the same way
EXTRA: If for some chance you are using devise you can get the ID too:
#[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
来源:https://stackoverflow.com/questions/23283926/response-from-smtp-server-with-rails