我想通過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