herokuでsmtpを使うためにsendgrid addonを入れる。(smtpにgmailを使う場合は要らない)

$ heroku addons:add sendgrid:starter
# config/environment.rb:

(snip)

ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.sendgrid.net',
  :port           => '587',                                                                                            
  :authentication => :plain,
  :user_name      => ENV['SENDGRID_USERNAME'],                                                                         
  :password       => ENV['SENDGRID_PASSWORD'],                                                                         
  :domain         => 'heroku.com',
  :enable_starttls_auto => true
}
# config/initializers/exception_notification.rb:
AppName::Application.config.middleware.use ExceptionNotification::Rack,
  :email => {
    :email_prefix => "[AppName] ",
    :sender_address => %{"notifier" <notifier@example.com>},
    :exception_recipients => %w{komagata@example.com}
  }
# Gemfile:
gem 'exception_notification'
# config/environments/production.rb:

(snip)

  # config.action_mailer.raise_delivery_errors = false
  config.action_mailer.raise_delivery_errors = true

(snip)

  config.action_mailer.perform_deliveries = true
end

Comments


(Option)