Ruby on Rails中的Sendgrid /电子邮件发送问题(在Heroku上托管) [英] Sendgrid / email sending issues in Ruby on Rails (hosted on Heroku)

查看:154
本文介绍了Ruby on Rails中的Sendgrid /电子邮件发送问题(在Heroku上托管)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果sendgrid在使用authlogic进行身份验证的rails 3.1应用程序中成功发送电子邮件,并且正在部署在heroku上,那么问题就出现了。我在config / environments / [development.rb和production.rb]上有以下动作邮件配置:

  config .action_mailer.delivery_method =:smtp 
config.action_mailer.default_url_options = {:host =>'localhost:3000'}
config.action_mailer.default_charset =utf-8
config.action_mailer .raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address =>'smtp.sendgrid.net',
:port => 587,
:domain => ENV ['SENDGRID_DOMAIN'],
:user_name => ENV ['SENDGRID_USERNAME'],
:password => ENV ['SENDGRID_PASSWORD'],
:authentication =>'plain',
:enable_starttls_auto => true
}



<对于production.rb,上面的代码是相同的,除了

  
config.action_mailer。 default_url_options = {:host => [heroku中的应用名称]}



当我运行它的开发模式,我得到以下错误报告:



  
在21740ms内完成了500次内部服务器错误
Net :: SMTPFatalError(550无法从指定地址收到通知@ [app-domain]:未经身份验证的发件人不允许
):



我现在不知道如何设置它以使其正常工作。有没有人在Heroku和Rails上设置sendgrid以前的经验知道发生了什么?



非常感谢你。你们是最棒的!!!

解决方案

我花了半天的时间,终于开始工作了。非常沮丧,因为它是由于一个糟糕的文档错误。我在Heroku上运行Rails 3.1和Cedar stack。

rel =noreferrer> http://devcenter.heroku.com/articles/sendgrid 会告诉你把你的SMTP设置的东西放在config / initializers / mail.rb中。但是...在 http:// docs .sendgrid.com / documentation / get-started / integrate / examples / rails-example-using-smtp / 它表示将所有SMTP设置填入config / environment.rb 而不是config / initializers /mail.rb



所以解决办法是把它放到你的environment.rb文件中。这是我的environment.rb的外观:

 #加载rails应用程序
需要File.expand_path('.. / application',__FILE__)

#初始化rails应用程序
Freelanceful :: Application.initialize!

#在Heroku上使用SendGrid的配置
ActionMailer :: Base.delivery_method =:smtp
ActionMailer :: Base.smtp_settings = {
:user_name => yourSendGridusernameyougetfromheroku,
:password => yourSendGridpasswordyougetfromheroku,
:domain => staging.freelanceful.com,
:address => smtp.sendgrid.net,
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true

$ / code>

要获得您的SendGrid用户名和密码,请键入

  $ heroku config -long 



<希望这可以帮助..和更多的人在这个头痛的未来。


im having a problem getting sendgrid to send emails successfully on a rails 3.1 app that's using authlogic for authentication and is being deployed on heroku. i have the following action mailer configuration on config/environments/[development.rb and production.rb]:

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.default_charset = "utf-8"
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :domain => ENV['SENDGRID_DOMAIN'],
  :user_name =>  ENV['SENDGRID_USERNAME'],
  :password => ENV['SENDGRID_PASSWORD'],
  :authentication => 'plain',
  :enable_starttls_auto => true
}

for production.rb, the above code is the same except for


    config.action_mailer.default_url_options = { :host => [app name in heroku] }

when i run it development mode, i get the following error reported:


    Completed 500 Internal Server Error in 21740ms
    Net::SMTPFatalError (550 Cannot receive from specified address notification@[app-domain]: Unauthenticated senders not allowed
):

i now dont really know how to set it up to get it working. does anyone with some prior experience on setting up sendgrid on heroku and rails know what's going on?

thank you so much. you guys are the best!!!

解决方案

I spent half a freakin' day on this and finally got mine working now. Quite frustrated as it was due to a poor documentation error. I'm running Rails 3.1 and Cedar stack on Heroku by the way.

So http://devcenter.heroku.com/articles/sendgrid will tell you to put your SMTP settings stuff in config/initializers/mail.rb. BUT... on http://docs.sendgrid.com/documentation/get-started/integrate/examples/rails-example-using-smtp/ it says to put all your SMTP settings stuff in config/environment.rb instead of config/initializers/mail.rb

So the solution is to put that in your environment.rb file. This is how my environment.rb looks:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Freelanceful::Application.initialize!

# Configuration for using SendGrid on Heroku
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :user_name => "yourSendGridusernameyougetfromheroku",
  :password => "yourSendGridpasswordyougetfromheroku",
  :domain => "staging.freelanceful.com",
  :address => "smtp.sendgrid.net",
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

To get your SendGrid username and password, type

$ heroku config -long

Hope that helps.. and more people in the future of this headache.

这篇关于Ruby on Rails中的Sendgrid /电子邮件发送问题(在Heroku上托管)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆