【发布时间】:2015-11-22 11:43:26
【问题描述】:
Heroku 文档说: https://devcenter.heroku.com/articles/sendgrid#ruby-rails
To send out emails through SendGrid, you need to configure the Mail class to have the correct values:
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
end
Mail gem 文档或 heroku 都没有明确指定 Mail 类应该在哪里以及如何配置它。
过去我只使用过类似的 Action Mailer
class UserMailer < ActionMailer::Base
default from: 'careerswitch.me@gmail.com'
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.user_mailer.signup_confirmation.subject
def signup_confirmation(user,subject_param='Welcome!')
@user = user
mail to: user.email,
subject: subject_param do |format|
#format.text {render __method__}
format.html {render __method__}
end
end
end
关于发生了什么变化以及如何在 Heruku/Rails4.1 上设置 sendgrid 的任何好的示例?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 heroku sendgrid