Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails中的Sendgrid/电子邮件发送问题(托管在Heroku上)_Ruby On Rails_Heroku_Actionmailer_Sendgrid - Fatal编程技术网

Ruby on rails RubyonRails中的Sendgrid/电子邮件发送问题(托管在Heroku上)

Ruby on rails RubyonRails中的Sendgrid/电子邮件发送问题(托管在Heroku上),ruby-on-rails,heroku,actionmailer,sendgrid,Ruby On Rails,Heroku,Actionmailer,Sendgrid,我在让sendgrid在rails 3.1应用程序上成功发送电子邮件时遇到问题,该应用程序使用authlogic进行身份验证,并且正在heroku上部署。我在config/environments/[development.rb和production.rb]上有以下action mailer配置: config.action\u mailer.delivery\u method=:smtp config.action\u mailer.default\u url\u options={:host

我在让sendgrid在rails 3.1应用程序上成功发送电子邮件时遇到问题,该应用程序使用authlogic进行身份验证,并且正在heroku上部署。我在config/environments/[development.rb和production.rb]上有以下action mailer配置:

config.action\u mailer.delivery\u method=:smtp
config.action\u mailer.default\u url\u options={:host=>'localhost:3000'}
config.action\u mailer.default\u charset=“utf-8”
config.action\u mailer.raise\u delivery\u errors=true
config.action\u mailer.perform\u deliveries=true
config.action\u mailer.smtp\u设置={
:address=>smtp.sendgrid.net',
:端口=>587,
:domain=>ENV['SENDGRID_domain'],
:user_name=>ENV['SENDGRID_USERNAME'],
:password=>ENV['SENDGRID_password'],
:身份验证=>“普通”,
:enable_starttls_auto=>true
}

对于production.rb,除了


config.action\u mailer.default\u url\u options={:host=>[app name in heroku]}

运行it开发模式时,报告了以下错误:


在21740毫秒内完成500个内部服务器错误
Net::SMTPFatalError(550无法从指定地址接收通知@[应用程序域]:不允许未经身份验证的发件人
):

我现在真的不知道如何设置它来让它工作。有在heroku和rails上建立sendgrid的经验的人知道发生了什么吗


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

我想你指的是本地的开发模式?如果是这样,我认为SendGrid插件不允许您从Heroku网络外部发送电子邮件(因为他们有独立帐户,希望您使用)

也就是说,在使用SendGrid插件时,您不需要在生产环境中配置邮件,因为它在部署应用程序时是自动配置的


因此,你可以删除你的
config.action\u mailer.smtp\u设置
代码,只需在开发过程中使用默认设置。

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

因此,我将告诉您将SMTP设置内容放入config/initializers/mail.rb。但是上面写着将所有SMTP设置内容放在config/environment.rb中,而不是config/initializers/mail.rb

因此,解决方案是将其放在environment.rb文件中。以下是my environment.rb的外观:

# 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
}
要获取SendGrid用户名和密码,请键入

$ heroku config -long

希望对你有帮助。。还有一点需要注意的是,如果你在竹堆上运行Heroku应用程序,你不需要在environment.rb文件中配置你的设置,因为Heroku是为你做的


但是,在您将应用程序激活到Heroku以设置这些设置后,您确实需要git推送至少一次。我今天早上犯了那个错误,找到了你的帖子

我在production.rb中注释掉了smtp_设置,根据heroku日志,我得到了一个连接拒绝错误。Errno::EconRefused(连接被拒绝-连接(2)):我是否应该将sendgrid作为gem包含在gem文件中?不,您应该只需要将加载项添加到应用程序中,然后执行部署。@NeilMiddleton Heroku文档确实声明您应该在Cedar堆栈上添加smtp_设置。如果是白杨树或竹子,你可以把它删掉。我不知道为什么,但我必须在mail.rb中进行配置。staging.rb对我不起作用。我在Heroku+Desive 2.0+sendgrid上运行Rails 3.1+Cedar stack。对不起,这是我的错误。这是一个配置问题。Heroku中的RACK_ENV和RAILS_ENV是“生产”,但我编辑了config/environments/staging.rb。首先,不要直接使用密码和用户名。使用环境变量,这就是它们的用途。第二:初始值设定项或env文件中的值无关紧要。环境文件最终加载初始值设定项文件。名字也不重要。我也有这个问题,多亏了Heroku的医生。但是,您可以将SMTP设置保留在
config/initializers/mail.rb
中,只要您不将
ActionMailer::Base.delivery\u method=:SMTP
放在
mail.rb
中,并且不要忘记像我那样在Heroku上实际设置环境变量。heroku配置:add SENDGRID\u USERNAME=foo和heroku配置:add SENDGRID\u PASSWORD=bar

    Completed 500 Internal Server Error in 21740ms
    Net::SMTPFatalError (550 Cannot receive from specified address notification@[app-domain]: Unauthenticated senders not allowed
):
# 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
}
$ heroku config -long