私のアプリには、ユーザーが名前/メール/件名/コンテンツを入力してメッセージを送信できる連絡先ページがあります。私はHerokuにSendgridアドオンを使用しており、ほとんどすべてが正しく行われたと思います。私はこれを持っています
emails_controller.rb
if @email.save
ContactMailer.contact_message(@email).deliver
flash.now[:success] = "Your email has sent! I'll try to get back to you shortly."
render :new
else
flash.now[:error] = "Please correct the highlighted errors and try again."
render :new
end
(ここでのアイデアは、各電子メールの記録を保持し、それを私に送信することです)。
私のconfig/initializers / mail.rb
# SendGrid Settings
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:enable_starttls_auto => true,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'myappname.com'
}
ActionMailer::Base.delivery_method = :smtp
次に、適切な方法として、sendgridサポートの質問で他の誰かが行ったことを追跡します。config / environment / product.rb:
config.action_mailer.default_url_options = { :host => 'myappname.com' }
私のcontact_email.html.erb:
class Contact < ActionMailer::Base
default from: "unimportant@example.com"
def contact_message(email)
@name = email.name
@address = email.address
@subject = email.subject
@content = email.content
mail(:to => ENV['EMAIL_ADDRESS'], :subject => @subject)
end
end
必要な環境変数をすべて追加しました
heroku config:add EMAIL_ADDRESS=blah@blah.com
heroku config:add SENDGRID_USERNAME=blah
しかし、herokuにプッシュして自分にメールを送信しようとすると、「ごめんなさい。何かがうまくいかなかった」という死の画面が表示され、ログは(私の目には)まったく役に立たない。
これは、最後にherokuにプッシュして、自分にメールを送信しようとしたときからのログです。何がうまくいかない可能性があるアイデアはありますか?
2013-02-03T20:34:18+00:00 heroku[router]: at=info method=GET path=/ host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=7ms service=201ms status=304 bytes=0
2013-02-03T20:34:18+00:00 heroku[router]: at=info method=GET path=/assets/application-cd9c41b78562d03bb04bcaaa585b31e8.js host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=1ms service=11ms status=200 bytes=125507
2013-02-03T20:34:19+00:00 heroku[router]: at=info method=GET path=/assets/pig3-b2d5155bd2811a87cafec6a447459580.png host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=1ms service=4ms status=200 bytes=3010
2013-02-03T20:34:19+00:00 heroku[router]: at=info method=GET path=/assets/github-e8c3b3f49b0cc737afe9b3cd6e9ab159.png host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=1ms service=4ms status=200 bytes=3687
2013-02-03T20:34:19+00:00 heroku[router]: at=info method=GET path=/assets/odesk2-38dadc2e6b0e94aa6c6766df301716bc.png host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=1ms connect=2ms service=4ms status=200 bytes=3932
2013-02-03T20:34:19+00:00 heroku[router]: at=info method=GET path=/assets/star-02718a47b29575c2d7a0e75ac8bebf4d.png host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=2ms service=4ms status=200 bytes=3104
2013-02-03T20:34:19+00:00 heroku[router]: at=info method=GET path=/assets/empty_star-9bf002077eafec40cf239068f7d4d1ca.png host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=1ms service=43ms status=200 bytes=3072
2013-02-03T20:34:23+00:00 heroku[router]: at=info method=GET path=/emails/new host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=1ms service=119ms status=200 bytes=3022
2013-02-03T20:34:23+00:00 heroku[router]: at=info method=GET path=/assets/application-74fd2354261a1131b26861b47bef1d87.css host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=2ms service=4ms status=304 bytes=0
2013-02-03T20:34:19+00:00 heroku[router]: at=info method=GET path=/assets/headshot-767c8913c7af4fc97cb8e15881884f0e.png host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=4ms connect=6ms service=11ms status=200 bytes=146892
2013-02-03T20:34:39+00:00 heroku[router]: at=info method=POST path=/emails host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=7ms service=131ms status=500 bytes=643
2013-02-03T20:34:39+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=<appname>-2591.herokuapp.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=1ms connect=3ms service=5ms status=200 bytes=0
また、Sendgridを追加しました(Herokuの指示に従いました)。Sendgridのユーザーインターフェイスには、送信された電子メールが表示されません。そして、これを最後に試したとき、次の行は、別のメッセージを送信しようとしたときに関連してタイムスタンプが付けられたherokuログの唯一の行のようでした。あまり役に立たない:
2013-02-04T18:15:45+00:00 heroku[router]: at=info method=GET path=/contact host=myappname.com fwd=69.181.104.85 dyno=web.1 queue=0 wait=0ms connect=2ms service=334ms status=200 bytes=3695