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

时间:2023-01-16 10:56:03

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]:

我有一个问题,让sendgrid在rails 3.1应用程序上成功发送电子邮件,该应用程序使用authlogic进行身份验证,并部署在heroku上。在配置/环境/[开发]上,我有以下操作mailer配置。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
}

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

用于生产。rb,上面的代码除了


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

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

当我运行it开发模式时,我得到如下错误报告:


    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?

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

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

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

3 个解决方案

#1


43  

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.

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

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

所以http://devcenter.heroku.com/articles/sendgrid会告诉您将SMTP设置放在配置/初始化器/mail.rb中。但是…在http://docs.sendgrid.com/documentation/get-started/integrate/examples/rails-example- usingsmtp/上,它说要将所有SMTP设置放在config/environment中。rb的配置/初始化/ mail.rb

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

所以解决方法就是把它放到你的环境中。rb文件。这就是我的环境。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
}

To get your SendGrid username and password, type

要获取SendGrid用户名和密码,请输入

$ heroku config -long

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

希望帮助. .越来越多的人在未来的这个头疼。

#2


0  

I'm assuming you mean development mode as in locally? If so, I don't think the SendGrid add-on let you send email from outside the Heroku network (as they have standalone accounts that they would prefer you to use).

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

Saying that, you don't need to configure mail in production when using the SendGrid add-on as it is automagically configured for you when you deploy your application.

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

Therefore you can remove your config.action_mailer.smtp_settings code and simply use the default in development.

因此,可以删除config.action_mailer。smtp_settings代码,只在开发中使用默认值。

#3


0  

Also note that if you're running your Heroku app on the Bamboo stack you don't need to configure your settings in the environment.rb file since Heroku does it for you.

还要注意,如果你在竹签上运行Heroku应用程序,你不需要在环境中配置你的设置。rb文件,因为Heroku为你做的。

However you do need to git push at least once after you activated the app to Heroku to set these settings. I made that mistake this morning and found your post.

但是,在激活应用程序到Heroku设置这些设置之后,您至少需要启动一次git。我今天早上犯了那个错误,找到了你的职位。

#1


43  

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.

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

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

所以http://devcenter.heroku.com/articles/sendgrid会告诉您将SMTP设置放在配置/初始化器/mail.rb中。但是…在http://docs.sendgrid.com/documentation/get-started/integrate/examples/rails-example- usingsmtp/上,它说要将所有SMTP设置放在config/environment中。rb的配置/初始化/ mail.rb

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

所以解决方法就是把它放到你的环境中。rb文件。这就是我的环境。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
}

To get your SendGrid username and password, type

要获取SendGrid用户名和密码,请输入

$ heroku config -long

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

希望帮助. .越来越多的人在未来的这个头疼。

#2


0  

I'm assuming you mean development mode as in locally? If so, I don't think the SendGrid add-on let you send email from outside the Heroku network (as they have standalone accounts that they would prefer you to use).

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

Saying that, you don't need to configure mail in production when using the SendGrid add-on as it is automagically configured for you when you deploy your application.

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

Therefore you can remove your config.action_mailer.smtp_settings code and simply use the default in development.

因此,可以删除config.action_mailer。smtp_settings代码,只在开发中使用默认值。

#3


0  

Also note that if you're running your Heroku app on the Bamboo stack you don't need to configure your settings in the environment.rb file since Heroku does it for you.

还要注意,如果你在竹签上运行Heroku应用程序,你不需要在环境中配置你的设置。rb文件,因为Heroku为你做的。

However you do need to git push at least once after you activated the app to Heroku to set these settings. I made that mistake this morning and found your post.

但是,在激活应用程序到Heroku设置这些设置之后,您至少需要启动一次git。我今天早上犯了那个错误,找到了你的职位。