【问题标题】:Net::SMTPAuthenticationError 502 5.5.2 in Rails ActionMailerRails ActionMailer 中的 Net::SMTPAuthenticationError 502 5.5.2
【发布时间】:2011-03-23 08:02:51
【问题描述】:

我正在尝试向用户发送确认电子邮件。

但我收到以下错误:

Net::SMTPAuthenticationError (502 5.5.2 错误:命令无法识别

production.rb 中的配置如下:

# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = true

# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp

# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
  :address        => 'path_to_address_specified_by_my_hoster',
  :port           => 25,
  :domain         => 'my_domain.com',
  :authentication => :plain,
  :user_name      => 'signup@my_domain.com',
  :password       => 'password'
}

我在托管服务提供商的用户配置文件中创建了一个邮箱,名为“signup@my_domain.com”

对于创建的邮箱,他们发给我登录名和密码:

登录 = verbose_login

密码 = 详细密码

我没有完全理解 :user_name 的确切格式。

我应该使用

:user_name => "signup@my_domain.com"

或:

:user_name => "signup"

或:

:user_name => "verbose_login"

或者这个字段是特定于邮件服务器的,我必须请求托管服务提供商的支持?

:authentication => :plain 和 :login 有什么区别?

谢谢。

【问题讨论】:

    标签: ruby-on-rails authentication smtp actionmailer


    【解决方案1】:

    这对我很有效:

    config.action_mailer.smtp_settings = {
        :address              => 'smtp.gmail.com',
        :port                 => 587,
        :domain               => 'gmail.com',
        :user_name            => 'my_nick@gmail.com',
        :password             => 'secret_password',
        :authentication       => 'login',
        :enable_starttls_auto => true
      }
    

    更多信息here

    彼得

    【讨论】:

      【解决方案2】:

      我最近也遇到同样的错误,原因是收件人格式不正确

      recipient = IO.readlines(emails_filename).first
      mail(:to => recipient, :subject => subject)
      

      不要忘记添加strip 以获得干净的电子邮件地址。

      【讨论】:

        【解决方案3】:

        请尝试使用浏览器登录一次。 登录可能存在一些问题(它会询问验证码等)。

        成功登录后,请尝试使用 Rails Mailer。 它现在应该可以工作了。

        此问题通常发生在测试帐户上,因为我们通常不通过浏览器登录。 然后邮件提供商要求确认,例如验证码、出生日期或安全问题的答案等。

        【讨论】:

          【解决方案4】:

          我有同样的问题,但这只是一个谷歌配置问题。

          由于某种原因,Google 阻止了来自未知位置的访问(生产中的应用程序),所以要解决此问题,您可以转到 http://www.google.com/accounts/DisplayUnlockCaptcha 并单击继续(这将授予 10 分钟的访问权限以注册新应用程序)。

          另一方面,您可以登录您的 gmail 帐户,然后转到 https://www.google.com/settings/security/lesssecureapps 并启用对安全性较低的应用程序的访问,这就是我的解决方案!

          【讨论】:

            【解决方案5】:

            你必须使用 ActionMaliler::Base 而不是 config

               ActionMailer::Base.smtp_settings   #try this
            
              config.action_mailer.smtp_settings   #instead of this
            

            将您的 smtp 代码更改为以下。它现在应该可以工作了。

                  ActionMailer::Base.smtp_settings = {
                     :address        => 'path_to_address_specified_by_my_hoster',
                     :port           => 25,
                     :domain         => 'my_domain.com',
                     :authentication => :plain,
                     :user_name      => 'signup@my_domain.com',
                     :password       => 'password'
                      }
            

            【讨论】:

              猜你喜欢
              • 2014-05-23
              • 2015-01-12
              • 2018-01-12
              • 2011-10-20
              • 2017-06-07
              • 1970-01-01
              • 2014-11-27
              • 2014-11-02
              • 2015-02-07
              相关资源
              最近更新 更多