我有一個rails 4應用程序。我設置了ActionMailer,我可以通過localhost和gmail發送訂單確認電子郵件。Sendgrid設置在Rails 4上
我在Heroku上安裝了Sendgrid,並按照設置說明進行操作。我得到一個Net::SMTPSyntaxError (501 Syntax error
我的environment.rb(我有sendgrid用戶名/密碼在application.yml)
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
}
在production.rb
- 唯一actionamailer設置我已經是這樣的。我把它作爲一個佔位符來放置真正的域名。我目前正在使用herokuapp.com。
config.action_mailer.default_url_options = { host: 'localhost:3000' }
在我的orders_controller內的order create方法內,我在下面調用。
AutoNotifier.orderconf_email(current_user, @order).deliver
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
我缺少什麼?它在使用gmail的localhost上工作,所以我在sendgrid設置或production.rb文件的default_url中缺少一些東西。
你在生產中使用什麼堆棧?你有英雄配置中的ENV嗎?因爲heroku自動添加ENV的Bamboo堆棧上,雪松你需要手動添加它們,據我所知。 – 2014-09-04 19:54:36
我在雪松。是的,當我運行heroku配置時,我看到了sendgrid用戶/密碼。 – Moosa 2014-09-04 19:56:30
嘗試將production.rb中的主機更改爲bla-bla.herokuapp.com。實際上,我在production.rb中沒有config.action_mailer ...行,並且Sendgrid工作正常。 – 2014-09-04 19:58:34