venkat
venkat

Reputation: 836

Couldn't get email using devise Rails

I am implementing devise mailers for my application where i have done the following steps:

in model:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable
end

and then I added migrations of confirmation_token, confirmed_at, confirmation_sent_at

In devise.rb, I added:

  config.mailer_sender = '[email protected]'
  config.mailer = 'Devise::Mailer'

In development.rb:

config.assets.raise_runtime_errors = true

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {
      address:  'smtp.gmail.com',
      port:  587,
      domain: 'gmail.com',
      authentication: :plain,
      user_name: '[email protected]',
      password: 'example@123',
      enable_starttls_auto: true,
      openssl_verify_mode: 'none'
  }

All my credentials are fine. But the email is not generated. In my console i am getting mail information and link..

my console:

Sent mail to [email protected] (2597.8ms)
Date: Wed, 08 Apr 2015 23:39:09 +0530
From: [email protected]
Reply-To: [email protected]
To: [email protected]
Message-ID: <55256ec5ba47e_26f51d984dc117aa@itadmin-HP-Pavilion-17-Notebook-PC.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello [email protected]!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><a href="http://localhost:3000/users/password/edit?reset_password_token=M5os3tBYHQrsRaw4TtTt">Change my password</a></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

I haven't added any devise passwords controller / registartion controllers.

What might me the problem?

Upvotes: 2

Views: 158

Answers (1)

Uday kumar das
Uday kumar das

Reputation: 1613

You have to add this line of code in development.rb file:

config.action_mailer.delivery_method     = :smtp
config.action_mailer.perform_deliveries  = true
config.action_mailer.default_url_options = { host: 'localhost:3000' }

ActionMailer::Base.smtp_settings = { 
  address:             'smtp.gmail.com',
  port:                587,
  authentication:      :plain,   
  user_name:           '****@gmail.com',
  password:            '*****',
  openssl_verify_mode: 'none'
}

Upvotes: 2

Related Questions