简体   繁体   中英

amazon ses ActionMailer ruby on rails debug

I followed the recommendation here from Sujoy Gupta to use smtp to send emails on rails. I get no error on the console but the emails never seem to have reached ses: The statistics there show no email sent/received and I never got them in my inbox either. I added this to my config/environments/development.rb/test.rb/production.rb:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
      :address => "email-smtp.us-west-2.amazonaws.com",
      :port => 587, 
      :user_name => "...", # My SMTP user here.
      :password => "...", # My SMTP password here.
      :authentication => :login,
      :enable_starttls_auto => true
  }

and app/mailers/UserMailer.rb:

class UserMailer < ApplicationMailer
  default from: "user@hotmail.com"

  def test(email)
    mail(to: email, subject: 'ses test')
  end
end

Here is what printed in the console:

UserMailer.test("user@hotmail.com").deliver_now
  Rendered user_mailer/test.html.erb within layouts/mailer (0.1ms)

UserMailer#test: processed outbound mail in 16.2ms

Sent mail to user@hotmail.com (769.1ms)
Date: Wed, 11 Nov 2015 10:26:33 -0800
From: user@hotmail.com
To: user@hotmail.com
Message-ID: <56438859b7ee2_a6503fe78cc601fc19958@10ddb1e504ea.ant.amazon.com.mail>
Subject: ses test
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<html>
  <body>
    <!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    A quick brown fox jumped over the lazy dog.
  </body>
  </html>
  </body>
</html>

 => #<Mail::Message:70263775568080, Multipart: false, Headers: <Date: Wed, 11 Nov 2015 10:26:33 -0800>, <From: user@hotmail.com>, <To: user@hotmail.com>, <Message-ID: <56438859b7ee2_a6503fe78cc601fc19958@10ddb1e504ea.ant.amazon.com.mail>>, <Subject: ses test>, <Mime-Version: 1.0>, <Content-Type: text/html>, <Content-Transfer-Encoding: 7bit>>

Following the java documentation here , I was able to send an email successfully using the same host and smtp username/password.

Any idea what I might have wrong? Where can I find more logs to dig more into it?

Thanks!

Turns out I just needed to close and reopen the rails console. For some reason reloading it is not enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM