2011-07-04 11:00:28 +0900
HerokuのCedarスタックでSendgridを使うための設定について。
Herokuに新しく登場したCedarスタックでメールを送信するため、Sendgridアドオンを有効にしてWorkerのジョブからActionMailerを利用してメールを送信しようとしたところ、以下のようなエラーログが記録されました。
2011-07-01T11:34:29+00:00 app[worker.1]: Sent mail to foo@example.com (3065ms)
2011-07-01T11:34:29+00:00 app[worker.1]: [Worker(host:0ad8724e-50ca-b229-486b-542b1b07ba54 pid:1)] Class#usage_report_mail failed with Errno::ECONNREFUSED: Connection refused - connect(2) - 0 failed attempts
2011-07-01T11:34:29+00:00 app[worker.1]: [Worker(host:0ad8724e-50ca-b229-486b-542b1b07ba54 pid:1)] 1 jobs processed at 0.2842 j/s, 1 failed ...
Heroku | Dev Center | Sendgridを読んでみると、
If you’re not using Rails and ActionMailer, or you are using the Cedar stack, you will need to setup your email framework manually; check out examples below.
とあり、Cedarスタックでは明示的にActionMailerの設定を行うことが必要なようです。
というわけで、config/environments/production.rb
に以下の設定を追加してアプリケーションをheroku restart
したところ、問題なくメールの送信が行われるようになりました。
TestApp::Application.configure do
# ...
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "25",
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN']
}
end