我试着用xcode(安装了ruby)通过os x上的ruby(没有rails)发送简单的电子邮件,但是我的smtp服务器遇到了一个问题,它要求电子邮件客户端在以身份验证的形式发送邮件之前检查邮件。
在发送邮件之前,如何让ruby以“pop”的方式通过smtp服务器的身份验证?不是下载邮件;我只想发送html格式的电子邮件(最终通过applescript调用ruby,因为applescript不支持smtp),但服务器要求我在发送之前检查邮件。
编辑4/05/10:
好吧,那太尴尬了。结果变得更简单了;我试图让事情变得比需要的更复杂。即使我的邮件服务器在SMTP之前需要POP,这也会发送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