发送电子邮件通知时500内部服务器错误

时间:2015-08-15 21:48:52

标签: ruby-on-rails heroku

我使用Mailboxer gem在Heroku上,我正在尝试设置邮件的电子邮件通知。

邮件已创建,但在尝试通过电子邮件通知联系收件人时会超时。

消息控制器:

  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 = "no-reply@domain.com"

  #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:            'username@gmail.com',
    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@hotmail.com (60151.4ms) 
Aug 14 12:12:23 domain app/web.1:  Sent mail to email@hotmail.com (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'

2 个答案:

答案 0 :(得分:1)

要使用Gmail,您需要确保它可以绕过Google的现代安全协议。

虽然我可以解释如何操作,但我建议使用Mandrill,Sendgrid,Mailjet或其他电子邮件程序,因为Gmail只允许您每天通过电子邮件发送最多500个收件人。

就个人而言,我使用Mandrill并且喜欢在RoR之外设置电子邮件模板,运行A-B测试以及跟踪谁打开/查看电子邮件的能力。

答案 1 :(得分:0)

它说你在messages_controller.rb第15行

上有错误
  

应用程序/控制器/ messages_controller.rb:15