【问题标题】:gmail smtp with rails 3带有rails 3的gmail smtp
【发布时间】:2011-09-16 19:42:33
【问题描述】:

我正在尝试使用 gmail 帐户发送确认电子邮件。我环顾四周,没有什么是明显的。没有错误或任何东西,它只是不发送

我有这个作为初始化器:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true


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

ActionMailer::Base.default_url_options[:host] = "localhost:3000"

【问题讨论】:

  • 发送邮件时你的控制台输出是什么?

标签: ruby-on-rails-3 actionmailer


【解决方案1】:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => 'baci.lindsaar.net',
  :user_name            => '<username>',
  :password             => '<password>',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

&lt;username&gt; 的意思是填写你的真实用户名? &lt;password&gt;也是如此

【讨论】:

    【解决方案2】:

    至少在 Rails 3.2 中,您不再需要 tlsmail gem

    这就够了

    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => 'baci.lindsaar.net',
      :user_name            => '<username>',
      :password             => '<password>',
      :authentication       => 'plain',
      :enable_starttls_auto => true  }
    

    来自全能指南ActionMailer configuration for gmail

    【讨论】:

    • 太棒了,很高兴知道。省了我一大堆头痛。感谢您的提醒!
    • 没问题 ;) 我现在习惯了在 Rails 指南中搜索几乎所有内容
    • 显然,:domainoptional,尽管您不会从阅读 docs 中知道这一点。
    【解决方案3】:

    将 tlsmail 添加到 gemfile

    gem 'tlsmail'
    

    运行:

    bundle install
    

    将这些设置添加到 config/envirnoments/development.rb 文件中

    YourApplicationName::Application.configure do
        require 'tlsmail'
          Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
          ActionMailer::Base.delivery_method = :smtp
          ActionMailer::Base.perform_deliveries = true
          ActionMailer::Base.raise_delivery_errors = true
          ActionMailer::Base.smtp_settings = {
              :address => "smtp.gmail.com",
              :port => "587",
              :domain => "gmail.com",
              :enable_starttls_auto => true,
              :authentication => :login,
              :user_name => "<addreee>@gmail.com",
              :password => "<password>"
          }
    
        config.action_mailer.raise_delivery_errors = true
    

    【讨论】:

    • 别忘了重启服务器 ;)
    【解决方案4】:

    您应该检查 my_user_name@gmail.com 确实已发送电子邮件。我们过去在通过 Gmail 的 SMTP 服务器发送验证电子邮件时遇到过这个问题,因为批量发送最终根本不发送。

    我建议您登录 my_user_name@gmail.com 并确认没有问题并且电子邮件已发送。

    如果没有,您可能需要尝试Send Grid 之类的服务来发送外发电子邮件。

    或者,您可以查看您的服务器。或者,如果您正在开发中,请查看 log/development.log。我很确定您可以在日志中看到它实际上是在尝试发送邮件。

    问题在于 Google 不信任您的本地 IP 地址,因此您的邮件不会被递送(甚至不会递送到垃圾邮件目录)。没有办法解决这个问题,只能使用列入白名单的服务器。

    您可以通过将您的应用部署到 Heroku 等生产服务器并在那里进行测试来尝试这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多