我在使用郵箱gem的Heroku上嘗試設置郵件的電子郵件通知。500發送電子郵件通知時發生內部服務器錯誤
郵件已創建,但嘗試通過電子郵件通知聯繫收件人時超時。
消息控制器:
def create
@recipient = User.find(params[:user])
current_user.send_message(@recipient, params[:body], params[:subject])
flash[:notice] = "Message has been sent!"
if request.xhr?
render :json => {:notice => flash[:notice]}
else
redirect_to :conversations
end
end
Mailboxer.rb:
Mailboxer.setup do |config|
#Configures if you applications uses or no the email sending for Notifications and Messages
config.uses_emails = true
#Configures the default from for the email sent for Messages and Notifications of Mailboxer
config.default_from = "[email protected]"
#Configures the methods needed by mailboxer
config.email_method = :mailboxer_email
config.name_method = :name
#Configures if you use or not a search engine and wich one are you using
#Supported enignes: [:solr,:sphinx]
config.search_enabled = false
config.search_engine = :sphinx
end
用戶模型:
def mailboxer_email(object)
if self.no_email
email
else
nil
end
end
Production.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'domain.herokuapp.com' }
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: '[email protected]',
password: 'password',
authentication: 'plain',
enable_starttls_auto: false }
config.action_mailer.default_url_options = { :host => "domain.herokuapp.com" }
config.action_mailer.perform_deliveries = true
日誌:
Aug 14 12:11:23 domain app/web.1: Parameters: {"utf8"=>"✓", "user"=>"7", "subject"=>"inhereyes messaged you", "body"=>"Will the email send this time as notification?", "commit"=>"Send"}
Aug 14 12:11:23 domain app/web.1: Rendered vendor/bundle/ruby/2.0.0/gems/mailboxer-0.11.0/app/views/message_mailer/new_message_email.html.erb (0.6ms)
Aug 14 12:11:23 domain app/web.1: Rendered vendor/bundle/ruby/2.0.0/gems/mailboxer-0.11.0/app/views/message_mailer/new_message_email.html.erb (0.6ms)
Aug 14 12:11:23 domain app/web.1: Rendered vendor/bundle/ruby/2.0.0/gems/mailboxer-0.11.0/app/views/message_mailer/new_message_email.text.erb (0.2ms)
Aug 14 12:11:23 domain app/web.1: Rendered vendor/bundle/ruby/2.0.0/gems/mailboxer-0.11.0/app/views/message_mailer/new_message_email.text.erb (0.2ms)
Aug 14 12:11:52 domain heroku/router: at=error code=H12 desc="Request timeout" method=POST path="/messages" host=domain.com request_id=b00e5acf-3342-4e80-913e-610c5be6d83c fwd="73.54.214.248,108.162.237.126" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0
Aug 14 12:12:23 domain app/web.1: Sent mail to [email protected] (60151.4ms)
Aug 14 12:12:23 domain app/web.1: Sent mail to [email protected] (60151.4ms)
Aug 14 12:12:23 domain app/web.1: Completed 500 Internal Server Error in 60210ms
Aug 14 12:12:23 domain app/web.1: Completed 500 Internal Server Error in 60210ms
Aug 14 12:12:23 domain app/web.1: Net::ReadTimeout (Net::ReadTimeout):
Aug 14 12:12:23 domain app/web.1: app/controllers/messages_controller.rb:15:in `create'
Aug 14 12:12:23 domain app/web.1: app/controllers/application_controller.rb:27:in `user_time_zone'
Aug 14 12:12:23 domain app/web.1: Net::ReadTimeout (Net::ReadTimeout):
Aug 14 12:12:23 domain app/web.1: app/controllers/messages_controller.rb:15:in `create'
Aug 14 12:12:23 domain app/web.1: app/controllers/application_controller.rb:27:in `user_time_zone'
我認爲這只是Heroku超時30秒後,您的請求持續多久? – 2015-08-15 22:00:23