我有一个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