【问题标题】:Rails smtp issueRails smtp 问题
【发布时间】:2019-08-20 13:46:24
【问题描述】:

我是初级 Rails 开发人员。 我试图通过 gmail.com 的 smtp 发送电子邮件 我在互联网上找到了this article。 我的environments/production.rb

  config.action_mailer.delivery_method = :sendmail
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_options = {from: 'pangodfather@gmail.com'}

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      address:              'smtp.gmail.com',
      port:                 587,
      domain:               'devb.carwash.it',
      user_name:            'myaccount@gmail.com',
      password:             'mypass',
      authentication:       'plain',
      enable_starttls_auto: true
  }

这样我尝试发送邮件

   UserNotificationMailer.send_change_password_link(@user, params[:user][:password]).deliver_now

我有这个错误。 Net::SMTPSyntaxError(501 语法:HELO 主机名

如果我运行 hostname 在我的服务器上 主机名,输出为:

devb.carwash.it

我做错了什么? 谢谢

【问题讨论】:

  • 尝试使用gmail.com 代替devb.carwash.it 设置域

标签: ruby-on-rails ruby linux centos smtp


【解决方案1】:

域应该是gmail.com,您已将其设置为您自己的域,但这是不正确的。

From Ruby docs:

HELO 域

在几乎所有情况下,您都必须提供第三个参数 ::开始/SMTP#开始。这是您所在的域名(主机 发送邮件)。它被称为“HELO 域”。 SMTP 服务器 将通过以下方式判断是否应该发送或拒绝 SMTP 会话 检查 HELO 域。

示例配置:

config.action_mailer.smtp_settings = {
      address:              'smtp.gmail.com',
      port:                 587,
      domain:               'gmail.com',
      user_name:            'myaccount@gmail.com',
      password:             'mypass',
      authentication:       :plain,
      enable_starttls_auto: true
  }

【讨论】:

  • 错误信息?
  • 是一样的:(
  • 好的一些事情。你在生产中测试吗?如果没有,您应该将其移至 development.rb。其次,我需要你提供更多信息。使用您最近尝试的日志和对代码的更改来编辑您的帖子。
  • 好的,所以我只是测试从命令行通过 smtp 发送邮件,这工作正常。如何获取有关错误的更多信息?
  • 当然,我在生产环境中进行测试
【解决方案2】:

让我分享一下我在使用 Gmail 解决此问题时遇到的问题。

  1. 首先启用不太安全的应用登录到 Gmail。

    访问您的gmail settings 并启用安全性较低的应用以使应用正常运行。

  2. 将:authentication key的值:plain改为:login

  3. 如果您已启用两步验证以访问 Gmail,则必须向您的应用授予权限。

希望这会有所帮助:)

【讨论】:

    【解决方案3】:

    所以很遗憾,我无法解决这个问题。 我的解决方法是不要使用动作邮件程序的 mail(),而是使用 Mail gem - 它工作正常。

    【讨论】:

      猜你喜欢
      • 2011-10-19
      • 2011-03-05
      • 2023-02-14
      • 2011-09-03
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 2016-11-25
      • 2011-05-02
      相关资源
      最近更新 更多