简体   繁体   中英

How to send confirmation e-mails using gmail smtp service for registration using devise under development mode locally?

I have an app , it uses devise to send confirmation mails for the newly registered users , I have smtp settings under the development.rb file as

  config.action_mailer.default_url_options = { :host => 'http://localhost:3000' }
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
  :enable_starttls_auto => true,
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "gmail.com",
  :authentication => :login,
  :user_name => "my_username@gmail.com",
  :password => "mygmail password"
    }

This is throwing me with an error like ,

Net::SMTPAuthenticationError in Devise::RegistrationsController#create

535-5.7.1 Please log in with your web browser and then try again. Learn more at

Any Ideas how to resolve this ?

Resolved using these settings ..

 config.action_mailer.default_url_options = { :host => 'localhost:3000' }
 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            => "my_username@gmail.com",
  :password             => 'my_gmail password',
  :authentication       => "plain",
  :enable_starttls_auto => true
  }

I was unuable to resolve this problem with any code. After a while i logged in to gmail account and this is, what it gave me after.

We've detected suspicious activity on your Google Account. Please create a new password to continue using your account.

Read some tips on creating a secure password. 

So solution to this problem is simply log into account you use for email sending and reconfirm your new password

:authentication =>'plain'

# ActionMailer Config

config.action_mailer.default_url_options = {:host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# change to false to prevent email from being sent during development
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"

config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "example.com",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: "your_mail@gmail.com",
  password: "your_password"
}

After making your development.rb file like this, then if you have problem means please login to your gmail account, which is used in the development.rb file. Then problem will be solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM