【问题标题】:Getting Devise 1.3.4 to send emails with Gmail in development让 Devise 1.3.4 在开发中使用 Gmail 发送电子邮件
【发布时间】:2011-08-21 11:54:10
【问题描述】:

我正在尝试将 devise 1.3.4 设置为在开发模式下通过 gmail 发送电子邮件。我应该提到我正在使用 Rails 3.0.4 和 Ruby 1.9.2p136。

我在 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  
}  

在 config/initializers/devise.rb 我改变了

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

 config.mailer_sender = "info@mydomain.com"

然后我尝试了

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

还是不行。

是否有关于如何让邮件程序正常工作的 wiki 页面?我在日志中看到了电子邮件,它看起来很棒!链接有效,等等……我只想在我的电子邮件帐户中看到它们。


编辑

我找到了答案—— 我使用了http://yekmer.posterous.com/devise-gmail-smtp-configuration - 当我应该把它放在 config/environments/development.rb 中时,我一直把它放在 config/initializers/devise.rb 中。

【问题讨论】:

  • 标识您如何解决此问题的链接不再有效。你能在你的帖子中添加更多细节吗?
  • 这是一个完整的 Rails 项目,我已经开源,其中包含带有 gmail 的邮件和设计设置。 github.com/cyrusstoller/RevTilt 如果您需要帮助设置 config/initializers/setup_mail.rb 中使用的环境变量,请告诉我

标签: ruby-on-rails devise actionmailer


【解决方案1】:

你试过了吗?

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 
} 

--------- 编辑

它已发送,可能由于垃圾邮件过滤器而您没有收到它,首先要检查:

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

【讨论】:

  • 用我拥有的 gmail 帐户尝试过。它仍然说电子邮件已发送,但我从未收到它。我将该代码放在 ActionMailer::Base.smtp_settings 的块中。
  • 尝试然后进入该帐户并检查邮件是否已发送
  • 我正在使用谷歌应用程序。我刚刚登录看看它是否发送了任何电子邮件......看起来它没有。
  • 我想让 Devise 邮件程序工作,但如果不能,我想我可以自己写一个 groups.google.com/group/plataformatec-devise/browse_thread/…
  • 感谢您的帮助。我想通了 - 我把我的解决方案放在上面。
【解决方案2】:

你应该把它放在设计初始化器中:

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

然后创建一个扩展 Devise::Mailer 的类:

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

  def self.mailer_name
    "devise/mailer"
  end
end

【讨论】:

    【解决方案3】:

    我认为您可以在 config/initializers/devise.rb 中更改它。我认为不需要新课程?

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

    【讨论】:

      【解决方案4】:

      检查ActionMailer::Base.delivery_method的值是否为:smtp

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-26
        • 2020-07-12
        • 2019-10-16
        • 2023-03-13
        • 2021-09-11
        • 1970-01-01
        • 2022-06-17
        相关资源
        最近更新 更多