pwz2000
pwz2000

Reputation: 1395

500 Internal Server Error when sending email notification

I am on Heroku using the Mailboxer gem and am trying to setup email notifications for messages.

The message is created, but it time-out when attempting to contact the recipient via email notification.

Messages controller:

  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

User model:

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

Logs:

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'

Upvotes: 1

Views: 2393

Answers (3)

user1724295
user1724295

Reputation:

To use Gmail, you need to make sure that it can bypass Google's modern security protocols.

While I could explain how to do it, I instead recommend using Mandrill, Sendgrid, Mailjet, or another email program as Gmail only allows you to email a maximum number of 500 recipients to per day.

Personally, I use Mandrill and love the ability to set email templates outside of RoR, run A-B test, and track who opens / views the emails.

Upvotes: 1

user4776684
user4776684

Reputation:

Here it states that your email generation took about 60 seconds, and if I am not mistaken Heroku times out after 30 seconds.

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)

Upvotes: 1

Md Sirajus Salayhin
Md Sirajus Salayhin

Reputation: 5144

It say's you have an error on messages_controller.rb line number 15

app/controllers/messages_controller.rb:15

Upvotes: 0

Related Questions