【发布时间】:2020-03-16 17:18:12
【问题描述】:
我在 Rails 5.2 应用程序上使用 Sendgrid,得到了一个
Net::ReadTimeout 尝试发送电子邮件时出错。这里的帖子
https://github.com/mikel/mail/issues/639#issuecomment-29016055 建议在 SMTP 设置中添加 :tls => true。这行得通,但它似乎是一个旧的解决方案,我想了解它在做什么以及它为什么起作用。
这是我的 SMTP 设置,它给出了 Net::ReadTimeout 错误:
ActionMailer::Base.smtp_settings = {
:user_name => 'username',
:password => 'password',
:domain => 'mydomain.com',
:address => 'smtp.sendgrid.net',
:port => 465,
:authentication => :plain,
:enable_starttls_auto => true
}
这是正在运行的更新。
ActionMailer::Base.smtp_settings = {
:user_name => 'username',
:password => 'password',
:domain => 'mydomain.com',
:address => 'smtp.sendgrid.net',
:port => 465,
:authentication => :plain,
:enable_starttls_auto => true,
# this line added
:tls => true
}
【问题讨论】:
-
对 TLS 本身的概述很好,但没有在 Rails 上下文中回答问题。
-
它的字面意思是“:ssl/:tls - 启用 SMTP 连接以使用 SMTP/TLS(SMTPS:通过直接 TLS 连接的 SMTP)”。你还需要知道什么? guides.rubyonrails.org/action_mailer_basics.html
-
另外你使用了错误的端口。 “对于未加密或 TLS 连接,请使用端口 25、2525 或 587”sendgrid.com/docs/API_Reference/SMTP_API/…
-
:tls用于隐式 TLS,即smtps端口 465。STARTTLS 用于在端口 25 和 587 上使用smtp的显式 TLS。
标签: ruby-on-rails ssl sendgrid-rails