Moo*_*osa 6 ruby-on-rails heroku sendgrid
我有一个rails 4应用程序.我设置了ActionMailer,我可以通过localhost和gmail发送订单确认电子邮件.
我在Heroku上安装了Sendgrid并按照设置说明进行操作.我得到了 Net::SMTPSyntaxError (501 Syntax error
我的environment.rb(我在application.yml中有sendgrid用户/ pwd)
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
}
Run Code Online (Sandbox Code Playgroud)
在production.rb - 我唯一的actionamailer设置就是这个.我有这个作为占位符,以便在以后放置真正的域名.我目前正在使用herokuapp.com.
config.action_mailer.default_url_options = { host: 'localhost:3000' }
Run Code Online (Sandbox Code Playgroud)
在我的orders_controller命令创建方法中,我调用下面的内容.
AutoNotifier.orderconf_email(current_user, @order).deliver
Run Code Online (Sandbox Code Playgroud)
auto_notifier.rb
class AutoNotifier < ActionMailer::Base
default from: "Test Email"
def orderconf_email(current_user, order)
@buyer = current_user
@order = order
mail(to: @buyer.email, subject: 'Thank you for your order.')
end
end
Run Code Online (Sandbox Code Playgroud)
我错过了什么?它适用于使用gmail的localhost,因此我在sendgrid设置或production.rb文件的default_url中缺少某些内容.
Ric*_*eck 23
对于后代,这是Heroku上Rails中外部SMTP的工作设置:
#config/environments/production.rb
config.action_mailer.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587, # ports 587 and 2525 are also supported with STARTTLS
:enable_starttls_auto => true, # detects and uses STARTTLS
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"], # SMTP password is any valid API key, when user_name is "apikey".
:authentication => 'login',
:domain => 'yourdomain.com', # your domain to identify your server when connecting
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5453 次 |
| 最近记录: |