Rails 4出现Net::SMTPAuthenticationError: 535 #5.7.0身份验证失败错误

8
我正在为我大学的一个学生组织建立电子邮件列表。该组织约有6000名成员,为避免成本,我已获得使用学校电子邮件服务器的许可,并且他们已为我创建了一个账户。
我已经使用我的邮件客户端测试了该账户,一切似乎都正常,但是当我尝试通过我的Rails 4应用程序发送时,出现了错误:
Net::SMTPAuthenticationError: 535 #5.7.0 Authentication failed

I have it configured like so:

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服务器“对公众完全开放”,没有任何阻止连接的东西,我们检查了他们的日志,他们甚至没有看到来自我的应用程序的连接尝试。

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


你能在邮件发送后发布操作日志吗? - Caffeine Coder
请务必继续检查垃圾邮件文件夹,因为多次测试某个功能会被谷歌视为垃圾邮件。 - Caffeine Coder
@CaffeineCoder 我没有使用谷歌。 - Deekor
在您的邮件发送程序文件中,您使用的电子邮件是什么? 请确保它与以下内容相同:检查端口是否打开或可访问, - 0bserver07
5个回答

6
尝试在您的操作邮件设置中添加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使用的库认为这是一个问题。 这里有一篇文章讨论了这个选项。


谢谢您的建议,不幸的是我仍然收到相同的错误信息。 - Deekor
2
你尝试过使用telnet或类似工具连接smtp服务器吗?这就是我找出配置问题的方法... - user3334690
@Deekor 嗯...你觉得你能把你连接到telnet的方法添加到问题中吗(当然要删减一些)? - user3334690
谢谢您的答案和提供原因的链接。这对我很有帮助。 - Benjamin

2
“: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
  }

好像没有什么区别。 - Deekor

1
在文件夹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"

这有什么不同于我正在做的呢? - Deekor

0

我按照以下步骤解决了我的问题。

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
}

由于谷歌会尝试阻止您的登录,如果您在帐户设置中关闭了对不安全应用程序的访问权限。因此,请按照此链接并"打开"不安全应用程序的访问权限。


0

域名中应该包含"http://"吗?


1
域名不应该影响服务器管理员。 - Deekor

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接