2010-08-02 72 views
2

我嘗試發送電子郵件的行動郵件,它給了我一個Timeout::Error (execution expired):即使它說,電子郵件發送控制檯: 它顯示Actionmailer「Timeout :: Error」的問題?

Sent mail to [email protected] 

然後裏顯示已發送,然後電子信箱它顯示了以下錯誤:

Timeout::Error (execution expired): 
    /usr/lib/ruby/1.8/timeout.rb:60:in `open' 
    /usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start' 
    /usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start' 
    /usr/lib/ruby/1.8/net/smtp.rb:525:in `start' 
    app/models/appointment.rb:10:in `tomorrows_appointments' 
    app/models/appointment.rb:8:in `each' 
    app/models/appointment.rb:8:in `tomorrows_appointments' 
    app/controllers/show_appointments_controller.rb:11:in `send_email' 
    -e:2:in `load' 
    -e:2 

Rendered rescues/_trace (35.8ms) 
Rendered rescues/_request_and_response (0.3ms) 
Rendering rescues/layout (internal_server_error) 

這裏是我的設置:

config.cache_classes = false 
config.whiny_nils = true 
config.action_controller.consider_all_requests_local = true 
config.action_view.debug_rjs       = true 
config.action_controller.perform_caching    = false 

config.action_mailer.raise_delivery_errors = true 
config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { 
    :enable_starttls_auto => true, 
    :address    => "smtp.gmail.com", 
    :port     => 587, 
    :domian    => "gmail.com", 
    :authentication  => :login, 
    :user_name   => "username", 
    :password    => "blablabla", 
} 

我還TR ied設置authentication:plain並使用[email protected]作爲user_name,沒有希望。

任何想法

回答

1

SMTP請求似乎偶爾超時,可能取決於你多長時間超時設置。當用戶等待您的服務器與Gmail的SMTP服務器進行通信時,您將遇到的另一個問題是網絡應用延遲。

我知道gmail是新的rails應用程序的流行選項,但我不認爲這是一個長期的解決方案,因爲您必須通過每天發送限制的特定gmail帳戶發送郵件。即使有其他帳戶,我也發現SMTP超時是一個問題。

現在我使用SendGrid發送電子郵件,並發現使用sendgrid作爲中繼器通過postfix是有利的選擇。這意味着用戶可以更快地獲得Web應用程序的響應,郵件通過Postfix排隊,然後通過sendgrid發送(因此不會超時!)。

在這裏看到sendgrid的後綴設置說明: http://wiki.sendgrid.com/doku.php?id=postfix

然後,在你的Rails環境,你只需要像下面這樣:

config.action_mailer.delivery_method = :sendmail 
config.action_mailer.sendmail_settings = { 
    :location  => '/usr/sbin/sendmail', 
    :arguments  => '-i -t' 
} 
3

我看到一個錯字有:你寫 : domian =>「gmail.com」,

而不是

:domain =>「 gmail.com」,

1

萬一別人有同樣的問題:

確保您的防火牆允許端口587

傳出連接對於iptables的,你可以列出所有現有的規則:

sudo iptables -L 

看看有沒有必要的規則here

如果您使用的是AWS實例,請查看您的安全組。