【问题标题】:Rails 4 Net::SMTPAuthenticationError: 535 #5.7.0 Authentication failedRails 4 Net::SMTPAuthenticationError: 535 #5.7.0 身份验证失败
【发布时间】:2014-11-02 07:39:18
【问题描述】:

我正在为我所在大学的一个学生组织建立一个电子邮件列表。该组织有大约 6000 名成员,为了避免费用,我已获得使用学校电子邮件服务器的许可,他们为我创建了一个帐户。

我已经使用我的邮件客户端测试了该帐户,一切似乎都运行良好,但是当我尝试通过我的 Rails 4 应用程序发送时,我收到了错误:

Net::SMTPAuthenticationError: 535 #5.7.0 Authentication failed

我是这样配置的:

application.rb

config.action_mailer.smtp_settings = 
{
    :address   => "smtp.school.edu",
    :port      => 25, 
    :enable_starttls_auto => true, 
    :user_name => "account@school.edu",
    :password  => "mypassword", 
    :authentication => 'login',
    :domain => 'http://myapp.herokuapp.com/' 
}

再一次,凭据都是正确的,我已经通过我的邮件客户端对其进行了测试,并且还与服务器管理员坐下来确认就端口和凭据而言,我的配置中的一切看起来都正确。

我被告知 smtp 服务器“对公众开放”,没有任何东西阻止连接,我们检查了他们的日志,他们甚至没有看到从我的应用程序连接的尝试。

有人知道这里出了什么问题吗?是否有一些我不知道的设置可能会关闭?

【问题讨论】:

  • 你能把邮件发送后的日志贴出来吗?
  • 还要继续检查垃圾邮件文件夹,因为一次又一次地测试某个功能会被谷歌视为垃圾邮件。
  • @CaffeineCoder 我没有使用谷歌。
  • 在您的邮件文件中,您使用的电子邮件是什么?确保它与检查端口是否打开或可访问相同,

标签: ruby-on-rails email ruby-on-rails-4 heroku actionmailer


【解决方案1】:

“:domain”应该指向“school.edu”而不是“herokuapp.com”吗?我知道当你通过 action_mailer 设置为 gmail 设置 smtp 时,你有类似的东西:

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

【讨论】:

  • 嗯似乎没有什么不同
【解决方案2】:

尝试将openssl_verify_mode => 'none' 添加到您的操作邮件设置中:

config.action_mailer.smtp_settings = 
{
    :address   => "smtp.school.edu",
    :port      => 25, 
    :enable_starttls_auto => true, 
    :user_name => "account@school.edu",
    :password  => "mypassword", 
    :authentication => 'login',
    :domain => 'http://myapp.herokuapp.com/',
    :openssl_verify_mode => 'none'
}

当然,我们使用的是 Rails 3,但这对我有用。对我们来说,问题是我们的证书是自签名的,Rails 使用的库认为这是一个问题。 这是一个article,它讨论了这个选项。

【讨论】:

  • 感谢您的建议,不幸的是我仍然收到相同的错误消息。
  • 您是否尝试过使用 telnet 等连接到 smtp 服务器?这就是我如何弄清楚我的配置出了什么问题...
  • @Deekor 嗯...您认为您可以将您通过 telnet 连接所做的事情添加到问题中(当然要擦洗一下)?
  • 感谢您的回答,以及原因的链接。这对我有帮助。
【解决方案3】:

域名是否应该包含“http://”?

【讨论】:

  • 根据服务器管理员,域应该无关紧要
【解决方案4】:

在文件夹config/initializers/中创建一个文件setup_mail.rb并放上代码:-

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
  :address   => "smtp.school.edu",
  :domain => 'myapp.herokuapp.com',
  :port      => 25,
  :user_name => "account@school.edu",
  :password  => "mypassword", 
  :authentication => :plain,
  :enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "myapp.herokuapp.com"

【讨论】:

  • 这和我做的有什么不同?
【解决方案5】:

我的问题已通过以下步骤解决。

config.action_mailer.default :charset => "utf-8"
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
    address: 'smtp.gmail.com',
    port: 587,
    domain: 'mysite.com',
    user_name: myemail@gmail.com,
    password: mypassword,
    authentication: 'plain',
    enable_starttls_auto: true
}

如果您在帐户设置中关闭了安全性较低的应用的访问权限,Google 会尝试阻止您的登录。因此,请按照此link 和“开启”访问权限来访问不太安全的应用程序。

【讨论】:

    猜你喜欢
    • 2018-02-08
    • 2021-07-30
    • 2013-08-07
    • 2015-04-12
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    相关资源
    最近更新 更多