Gmail SMTP 与 Rails 3

发布于 2024-11-16 08:26:25 字数 661 浏览 3 评论 0原文

我正在尝试使用 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"

I am trying to get a confirmation email sending using a gmail account. I have looked around and there is nothing that is obvious. There is no errors or anything, it just dosn't send

I have this as the initalizer:

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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

被翻牌 2024-11-23 08:26:25

至少在 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  }

来自全能指南 gmail 的 ActionMailer 配置

You don't need tlsmail gem anymore at least with Rails 3.2

This will be sufficient

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  }

From the all-mighty-guide ActionMailer configuration for gmail

情域 2024-11-23 08:26:25

将 tlsmail 添加到 gemfile

gem 'tlsmail'

run :

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

add tlsmail to gemfile

gem 'tlsmail'

run :

bundle install

add these settings to config/envirnoments/development.rb file

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
极致的悲 2024-11-23 08:26:25

您应该检查[电子邮件受保护] 是否已实际上发送了电子邮件。过去,我们在通过 Gmail 的 SMTP 服务器发送验证电子邮件时遇到过此问题,因为批量发送最终根本无法发送。

我建议您登录[email protected]并验证是否没有问题并且电子邮件已发送。

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

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

问题是 Google 不信任您的本地 IP 地址,因此您的邮件不会被发送(甚至不会发送到垃圾邮件目录)。除了使用白名单服务器之外,没有其他方法可以解决此问题。

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

You should check that [email protected] has actually sent the email. We have had issues with this in the past when sending verification emails out through Gmail's SMTP server, since sending in bulk end up not sending at all.

I suggest you log into [email protected] and verify that there are no problems and that the emails are sent.

If not, you may want try a service like Send Grid to send outgoing emails.

Alternatively, you can look into your server. Or if you are in development, have a look at log/development.log. I'm pretty sure that you can see in your logs that it's actually trying to send the mail.

The problem is that Google doesn't trust your local IP address and your mails won't get delivered (not even to the spam directory). There is no way to work around this but using a white-listed server.

You can try this out by deploying your app into a production server like Heroku and test it there.

才能让你更想念 2024-11-23 08:26:25
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  }

的意思是填写你的真实用户名? 也是如此

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  }

The <username> means to fill in your real username? So does the <password>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文