2013-02-03 95 views
1

我的應用程序有一個聯繫頁面,用戶可以在其中輸入他們的名稱/電子郵件/主題/內容並給我發送消息。我將Sendgrid插件用於heroku,並認爲我已經完成了幾乎所有的事情。我在我的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 

(這裏的想法是讓每封電子郵件的記錄,並也將其發送給我)有這個。

我的配置/初始化/ 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支持的問題一樣。配置/環境/ production.rb:

config.action_mailer.default_url_options = { :host => 'myappname.com' } 

我contact_email.html.erb:

class Contact < ActionMailer::Base 
    default from: "[email protected]" 

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

回答

1

,因爲它並未顯示在儀表盤SendGrid了,我的猜測是,您的憑據是錯誤的應用程序。如果輸入heroku config,您是否看到SENDGRID_USERNAMESENDGRID_PASSWORD設置正確?

此外,您可能想嘗試設置傳遞錯誤以顯示在您的配置文件中。

config.action_mailer.raise_delivery_errors = true 
+0

剛剛添加了最後一行。我100%的用戶名是準確的,並且Sendgrid密碼沒有添加任何內容(並且出於某種原因,Sendgrid的儀表板表示我無法訪問我的帳戶詳細信息),所以我認爲這是正確的。我會再試一次,看看它是否會引發任何有趣的錯誤。謝謝! – Sasha

+1

這有什麼更新? – Swift

+0

是的!你的第一個建議已經死了。出於某種原因,該密碼已關閉,儘管我無法(並且仍然無法)訪問我的帳戶設置,但我能夠重置密碼並將其更改爲其他內容。當我這樣做時,電子郵件就像魔術一樣發送。 (忘記檢查直到現在,因此推遲更新)。謝謝! – Sasha

0

只是爲了澄清一點,您無法訪問SendGrid站點上的帳戶設置,因爲Heroku鎖定了它。您直接從Heroku界面調整相同的設置。

相關問題