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 docs或heroku都没有明确指定Mail类应该在哪里以及如何配置它。
过去我只是使用Action Mailer这样的东西
class UserMailer < ActionMailer::Base
default from: '[email protected]'
# 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
关于发生了什么变化以及如何在Herouku / Rails4.1上设置sendgrid的任何很好的例子?
Heroku为sendgrid提供添加。https://elements.heroku.com/addons/sendgrid
通过添加此选项,它将自动为您设置环境变量,即SENDGRID_USERNAME SENDGRID_PASSWORD
设置加载项后,您必须将其放入production.rb
ActionMailer::Base.smtp_settings = {
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'appname.herokuapp.com',
:address => "smtp.sendgrid.net",
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
Mailer类将保持与通常使用的类相同。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句