【发布时间】:2010-04-05 22:12:38
【问题描述】:
我正在尝试使用 XCode(安装 Ruby)在 OS X 上通过 Ruby(无 Rails)发送简单的电子邮件。但我的 smtp 服务器遇到了问题,需要电子邮件客户端之前检查邮件作为一种身份验证形式发送。
在发送邮件之前,如何让 Ruby 以“POP”方式向 smtp 服务器进行身份验证?不下载邮件;我只想发送 html 格式的电子邮件(最终通过 Applescript 调用 Ruby,因为 Applescript 不支持 smtp),但服务器要求我在发送之前检查邮件。
编辑 4/05/10:
嗯,这很尴尬。结果变得更简单了;我试图让它变得比它需要的更复杂。即使我的邮件服务器需要在 smtp 之前弹出,这发送 OK:
require 'net/smtp'
message = <<MESSAGE_END
From: Private Person <me@fromdomain.com>
To: A Test User <test@todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
MESSAGE_END
Net::SMTP.start('mail.mydomain.com', 25) do |smtp|
smtp.send_message message,
'mark@mydomain.com',
'mark@mydomain.com'
end
编辑 4/04/10:
这样我得到一个 500 无法识别的命令错误;不过,pop 服务器正在响应。
require 'net/smtp'
require 'net/pop'
message = <<MESSAGE_END
From: Private Person <me@fromdomain.com>
To: A Test User <test@todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
MESSAGE_END
Net::POP3.start('mail.mydomain.com', 110, 'mark@mydomain.com', 'password') do |pop|
// If this line is included,
// I get a printout of the number
// of emails on the server
// right before the error:
//
// puts pop.n_mails end
Net::SMTP.start('mail.markratledge.com',
25,
'localhost',
'mark@mydomain.com', 'password', :plain) do |smtp|
smtp.send_message message, 'mark@mydomain.com',
'mark@mydomain.com'
end
end
【问题讨论】:
-
如果 smtp 服务器上的 pop 不可用,为什么需要 pop 检查?
-
我的错;我的意思是说安全流行......
-
我怀疑在执行
pop.finish时出现 500 错误的原因是,如果您像上面那样将块传递给POP3.start,那么连接会在结束时自动为您关闭因此,通过输入pop.close,您将尝试关闭连接两次。 -
4/05/10 编辑可能有效,因为您无需身份验证即可向自己发送电子邮件。它可能只中继到其他需要 POP before SMTP 的域。
-
你是对的;它不适用于其他域。在 smtp 之前使用 POP 登录服务器仍在调整和接近;现在我收到“已请求 SMTP-AUTH 但缺少密码短语”错误。