我想通过Ruby(无轨)在OS X上发送简单的电子邮件,用XCode(它安装Ruby。)但我遇到了我的smtp服务器的问题,它需要电子邮件客户端在发送之前检查邮件作为身份验证的一种形式。红宝石用smtp发送邮件
在我可以发送邮件之前,如何让Ruby以“POP”方式验证smtp服务器?不下载邮件;我只想发送HTML格式的电子邮件(最终通过调用Ruby的Applescript,因为Applescript不支持smtp),但服务器要求在发送之前检查邮件。
编辑10年4月5日:
嗯,这是尴尬。原来简单些,我试图让它比需要的更复杂。虽然我的邮件服务器的SMTP之前需要流行,这发出了OK:
require 'net/smtp'
message = <<MESSAGE_END
From: Private Person <[email protected]>
To: A Test User <[email protected]>
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,
'[email protected]',
'[email protected]'
end
编辑10年4月4日:
有了这个,我得到一个500无法识别的命令错误;虽然pop服务器正在响应。
require 'net/smtp'
require 'net/pop'
message = <<MESSAGE_END
From: Private Person <[email protected]>
To: A Test User <[email protected]>
Subject: SMTP e-mail test
This is a test e-mail message.
MESSAGE_END
Net::POP3.start('mail.mydomain.com', 110, '[email protected]', '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',
'[email protected]', 'password', :plain) do |smtp|
smtp.send_message message, '[email protected]',
'[email protected]'
end
end
如果smtp服务器上没有弹出窗口,您为什么需要弹出检查? – 2010-04-03 04:22:29
我的错误;我的意思是说安全的流行...... – markratledge 2010-04-03 17:48:32
我怀疑当执行'pop.finish'时出现500错误的原因是,如果你在上面做的时候将一个块传递给'POP3.start',那么连接会自动在块的末尾关闭你,所以通过放入一个'pop.close'你试图关闭连接两次。 – mikej 2010-04-04 22:47:21