后缀和Rails 3.0 ActionMailer:STARTTLS 后失去连接
我在开发模式下使用 Ruby 1.9.2 和 Rails 3.0.4,并且尝试将其配置为从安装在同一机器上的 Postfix 服务器发送电子邮件(运行安装了 dovecot-postfix 软件包的 Ubuntu 10.04)尝试从 Rails 发送电子邮件,它在 Rails 中顺利通过,但在 Postfix 日志中显示错误(我已从下面的摘录中删除了域和 IP):
Feb 21 04:49:16 alpha postfix/smtpd[9060]: connect from alpha.mydomain.com[xxx.xxx.xxx.xxx]
Feb 21 04:49:16 alpha postfix/smtpd[9060]: lost connection after STARTTLS from alpha.mydomain.com[xxx.xxx.xxx.xxx]
Feb 21 04:49:16 alpha postfix/smtpd[9060]: disconnect from alpha.mydomain.com[xxx.xxx.xxx.xxx]
奇怪的部分是,当我从像 Thunderbird 这样的电子邮件客户端,它可以正常工作。
我知道开发模式有时不允许发送电子邮件,因此我将以下内容添加到environments/development.rb 文件中:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
#load mail server settings
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "mail.mydomain.com",
:port => 587,
:domain => 'mydomain.com',
:user_name => 'username',
:password => 'password',
:authentication => 'plain',
:tls => true,
:enable_starttls_auto => true }
I'm using Ruby 1.9.2 and Rails 3.0.4 in development mode and I'm trying to configure it to send emails from the Postfix server installed on the same box (Running Ubuntu 10.04 with the dovecot-postfix package installed) Whenever I attempt to send an email from Rails, it goes through cleanly in Rails but displays an error in the Postfix logs (I've removed domains and IPs from the excerpt below):
Feb 21 04:49:16 alpha postfix/smtpd[9060]: connect from alpha.mydomain.com[xxx.xxx.xxx.xxx]
Feb 21 04:49:16 alpha postfix/smtpd[9060]: lost connection after STARTTLS from alpha.mydomain.com[xxx.xxx.xxx.xxx]
Feb 21 04:49:16 alpha postfix/smtpd[9060]: disconnect from alpha.mydomain.com[xxx.xxx.xxx.xxx]
The strange part is that when I connect to the SMTP server from an email client like Thunderbird, it works with no problems.
I know development mode sometimes doesn't allow for sending emails so I added the following to the environments/development.rb file:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
#load mail server settings
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "mail.mydomain.com",
:port => 587,
:domain => 'mydomain.com',
:user_name => 'username',
:password => 'password',
:authentication => 'plain',
:tls => true,
:enable_starttls_auto => true }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只是从本地主机发送电子邮件,那么您不需要 SMTP 以及随之而来的所有身份验证问题。您可以直接使用sendmail 发送。
config.action_mailer.delivery_method = :sendmail
If you're just sending email from localhost, then you don't need SMTP and all the authentication issues that come with it. You can simply deliver with sendmail directly.
config.action_mailer.delivery_method = :sendmail
是否有可能您的证书无效,并且 Thunderbird 在发送电子邮件时回退到纯 SMTP?尝试在您的配置中禁用 TLS。
Is it possible that your certificate is not valid, and that Thunderbird falls back to plain SMTP when sending emails? Try disabling TLS in your config.