3
votes

I'm configuring email confirmation to be sent out after the user signs up using devise. I did everything what this says (https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users) but it still does not work.

Here are some codes:

//development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

//devise.rb
  config.mailer_sender = '[email protected]'
  # Configure the class responsible to send e-mails.
  config.mailer = "Mailer"

//Mailer.rb
class Mailer < Devise::Mailer
  helper :application 
  include Devise::Controllers::UrlHelpers 
  default template_path: 'devise/mailer' 
end

Do I need to configure something more in order to send email confirmation letter in development environment??

3

3 Answers

3
votes

Yes, You have to configure smtp settings for emails to be sent from like :

require 'tlsmail'
  Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
    ActionMailer::Base.delivery_method = :smtp
     config.action_mailer.perform_deliveries = true
     config.action_mailer.default :charset => "utf-8"
       ActionMailer::Base.smtp_settings = {
       :address              => "smtp.gmail.com",
       :port                 => 587,
       :user_name            => "YOUR_EMAIL",
       :password             => 'PASSWORD',
       :authentication       => "plain",
       :enable_starttls_auto => true
       }

Add above code to your development.rb in order to configure smtp settings. Do add your email and password in the code where required. Hopefully It will work fine!

1
votes

In addition to @Muhammad's answer, also include these line of codes on your development.rb

config.action_mailer.default_url_options = {host: 'your server' } # ex. localhost:3000
config.action_mailer.raise_delivery_errors = true # to raise error if smtp has error on setup
config.action_mailer.default :charset => "utf-8"
1
votes

In initializers/devise.rb config.mailer_sender = 'your email'

config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      address:              'smtp.gmail.com',
      port:                  465,
      domain:               'gmail.com',
      user_name:            'your email',
      password:             'your password',
      authentication:       'plain',
      enable_starttls_auto: true,
      ssl: true

  }