Getting Devise 1.3.4 to send emails with Gmail in development

自古美人都是妖i 提交于 2019-12-17 18:29:52

问题


I'm trying to setup devise 1.3.4 to send emails via gmail while in development mode. I should mention that I'm using Rails 3.0.4 and Ruby 1.9.2p136.

I've tried the following in config/environments/development.rb:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true

config.action_mailer.default_url_options = { :host => 'mydomain.com' }

ActionMailer::Base.smtp_settings = {  
  :address              => "smtp.gmail.com",  
  :port                 => 587,  
  :domain               => "mydomain.com",  
  :user_name            => "info",  
  :password             => "secret",  
  :authentication       => "plain",  
  :enable_starttls_auto => true  
}  

And in config/initializers/devise.rb I changed

 config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"

To

 config.mailer_sender = "info@mydomain.com"

Then I tried

http://yekmer.posterous.com/devise-gmail-smtp-configuration

It's still not working.

Is there a wiki page on how to get the mailer working? I see the email in my log and it looks great! The links work, etc ... I just want to see them in my email account.


Edit

I found the answer - I used http://yekmer.posterous.com/devise-gmail-smtp-configuration - I had been putting that code in config/intializers/devise.rb when I should have been putting it in config/environments/development.rb.


回答1:


Have you tried this?

config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {  
  :address              => "smtp.gmail.com",  
  :port                 => 587,  
  :domain               => "gmail.com",  
  :user_name            => "myinfo@gmail.com",  
  :password             => "secret",  
  :authentication       => "plain"
  # :enable_starttls_auto => true # I don't have this, but it should work anyway 
} 

--------- EDIT

it it's sent maybe you don't receive it because of the spam filter, first thing to check:

class UserMailer < ActionMailer::Base
  default :from => "myinfo@gmail.com"
  # ...
end



回答2:


you should put that in devise initializer :

# Configure the class responsible to send e-mails.
  config.mailer = "YourAppDeviseMailer"

Then create a class that extends Devise::Mailer :

class YourAppDeviseMailer < Devise::Mailer
  default :from => 'your_email'

  def self.mailer_name
    "devise/mailer"
  end
end



回答3:


I think you can change it inside config/initializers/devise.rb. No need for a new class I think?

#config/initializers/devise.rb
config.mailer_sender = 'youremail@gmail.com'



回答4:


Check if the value of ActionMailer::Base.delivery_method is :smtp



来源:https://stackoverflow.com/questions/5933969/getting-devise-1-3-4-to-send-emails-with-gmail-in-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!