Search code examples
ruby-on-railsactionmailerdelayed-job

Email is not delivering in rails app


I am trying to send email in my rails app and in logs I have seen following body

Sent mail to ravendra.kumar@kiwitech.com (97ms)
Date: Wed, 25 Feb 2015 08:13:57 +0000
From: ashish.singla@kiwitech.com
To: ravendra.kumar@kiwitech.com
Message-ID: <54ed84452dcca_71c16217f47382e@web-01-development.mail>
Subject: Ashish Singla is inviting you to read together...
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable

but email is not delivering.


Solution

  • At least your mailer class is working. If you are in development mode, ensure that you have the perform_deliveries option set to true.

    If not, go to your config/environments/development.rb file and write

    config.action_mailer.perform_deliveries = true
    

    If this setting is already set to true and you are not getting the emails, then probably your smtp settings are not properly set. You can set them in config/application.rb with something like following:

    config.action_mailer.smtp_settings = {
      :address        => 'smtp.office365.com',
      :port           => 587,
      :domain         => 'your-domain.com',
      :user_name      => 'user@your-domain.com',
      :password       => 'somePassword',
      authentication: :login,
      enable_starttls_auto: true
    }
    

    In this case, may be enabling the setting raise_delivery_errors will help you to diagnose problems. You can do that in your config/environments/development.rb file and writing:

    config.action_mailer.raise_delivery_errors = true
    

    Then you will get an exception when the email can't be sent and (hopefully) a description about the problem.

    And after reading your comment: after changing all these config settings, restart the delayed_job backend.