开发者

Rails Devise send mail

开发者 https://www.devze.com 2023-03-26 16:55 出处:网络
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 vie

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 the开发者_如何转开发se 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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号