简体   繁体   中英

Rails Devise send mail

I am a newbie to sending mails through rails. I have implemented devise in my project and now I want to send a welcome email and/or a password-reset email. What changes do I need to make in Devise views?? No errors are displayed, but still I don't receive any email.

I have followed these links and finally my devise.rb, development.rb and production.rb files are as follows:

=== devise.rb ===

 config.mailer_sender = "xxx@gmail.com"

===development.rb==

  config.action_mailer.raise_delivery_errors = false

  config.action_dispatch.best_standards_support = :builtin

  config.active_support.deprecation = :notify
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = false
  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.default :charset => "utf-8"


  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.active_support.deprecation = :log

 config.action_mailer.smtp_settings ={
 :enable_starttls_auto => true,
 :address            => 'smtp.gmail.com',
 :port               => 587,
 :tls                => true,
 :domain             => 'gmail.com',
 :authentication     => :plain,
 :user_name          => 'xxx@gmail.com',
 :password           => 'xxxxxx' 
 }

 =====production.rb===
 config.action_mailer.default_url_options = { :host => 'gmail.com' }

  config.active_support.deprecation = :notify
   config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors =false 
config.action_mailer.default :charset => "utf-8"

  config.action_mailer.smtp_settings = {
  :enable_starttls_auto => true,
  :address            => 'smtp.gmail.com',
  :port               => 587,
  :tls                  => true,
  :domain             => 'gmail.com',
  :authentication     => :plain,
  :user_name          => 'xxx@gmail.com',
  :password           => 'xxxxxx' 
 }

Try setting raise_delivery_errors = true like this:

config.action_mailer.perform_deliveries = true # Set it to false to disable the email in dev mode
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "localhost:3000" }


ActionMailer::Base.smtp_settings = {
                    :address        => "smtp.gmail.com",
                    :port           => 587,
                    :authentication => :plain,
                    :user_name      => "user@gmail.com",
                    :password       => "password"
}

Have you installed the 'tlsmail' gem?

Follow the link to send mails using gmail in rails

http://ionrails.com/2009/07/27/sending-mail-via-gmail-with-rails-actionmailer/

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