2010-11-30 151 views
3

我已經testmail.rb上一個CentOS 5 VM SELinux的寬容和iptables關:紅寶石郵件寶石,如何編寫腳本郵件

require 'rubygems' 
require 'mail' 

options = { :address    => "mail.domain.com", 
      :port     => 466, 
      :domain    => 'otherdomain.com', 
      :user_name   => '[email protected]', 
      :password    => 'topsecret', 
      :authentication  => 'plain', 
      :enable_starttls_auto => true } 
Mail.defaults do 
    delivery_method :smtp, options 
end 

mail = Mail.new do 
     from '[email protected]' 
     to '[email protected]' 
    subject 'This is a test email' 
     body File.read('body.txt') 
end 

puts mail.to_s 

當腳本運行的結果是這樣的:

Date: Tue, 30 Nov 2010 12:12:58 -0500 
From: [email protected] 
To: [email protected] 
Message-ID: <[email protected]> 
Subject: This is a test email 
Mime-Version: 1.0 
Content-Type: text/plain; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

test! 

「測試!」是body.txt的內容。

沒有電子郵件到達發送到帳戶。我們從發送到域管理員的smtp設置。我使用telnet在未加密的端口(25)上成功發送電子郵件到域,但沒有收到來自加密端口(466)的響應,可能是因爲我的telnet會話未加密?

在腳本執行期間,我可以通過哪些方法查看發生了什麼事情以進行故障排除?

更新: 嘗試重定向:> log.log 2> & 1,但沒有提供任何其他信息。

回答

7

您錯過了實際發送的行。嘗試添加

mail.deliver! 

到您的腳本的末尾。

+0

gratitudinus maximus! – 2010-11-30 17:17:54