16

認証にauthlogicを使用し、herokuにデプロイされているRails3.1アプリでsendgridがメールを正常に送信するのに問題があります。config / environment/[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 => [app name in heroku] }

開発モードで実行すると、次のエラーが報告されます。


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

私は今、それを機能させるためにそれを設定する方法を本当に知りません。herokuとrailsにsendgridをセットアップした経験のある人は、何が起こっているのか知っていますか?

どうもありがとうございます。君たちは最高です!!!

4

3 に答える 3

44

私はこれに半日を費やし、ついに私の仕事を始めました。ドキュメンテーションのエラーが原因だったので、かなりイライラしました。ところで、Heroku で Rails 3.1 と Cedar スタックを実行しています。

したがって、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 の外観です。

# 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

この頭痛の将来に役立つことを願っています..そしてより多くの人々。

于 2012-01-10T08:54:32.557 に答える
0

ローカルのように開発モードを意味していると思いますか?もしそうなら、SendGrid アドオンが Heroku ネットワークの外から電子メールを送信できるとは思わない (Heroku はスタンドアロンのアカウントを持っているので、Heroku の使用を望んでいるからだ)。

そうは言っても、SendGrid アドオンを使用する場合、本番環境でメールを構成する必要はありません。これは、アプリケーションをデプロイするときに自動的に構成されるためです。

したがって、config.action_mailer.smtp_settingsコードを削除して、開発時にデフォルトをそのまま使用できます。

于 2012-01-08T23:24:20.783 に答える
0

また、Bamboo スタックで Heroku アプリを実行している場合は、Heroku が自動的に行うため、environment.rb ファイルで設定を構成する必要はありません。

ただし、Heroku に対してアプリをアクティブ化してこれらの設定を行った後、少なくとも 1 回は git push する必要があります。私は今朝その間違いを犯し、あなたの投稿を見つけました。

于 2013-07-15T23:51:55.713 に答える