2010-02-21 11 views
5

我是新來的rails和使用rails-2.3.5和ruby-1.8.7。這裏是我的notifier.rb型號:Rails - 如何在不觸發Net :: SMTPFatalError的情況下使用完整的電子郵件地址?

# app/models/notifier.rb 
class Notifier < ActionMailer::Base 
    default_url_options[:host] = "foo.com" 

    #This method sends an email with token to users who request a new password 
    def password_reset_instructions(user) 
    subject  "Password Reset Instructions" 
    from   "Support Team<[email protected]>" 
    recipients user.email 
    sent_on  Time.now 
    body   :edit_password_reset_url => 
        edit_password_reset_url(user.perishable_token) 
    end 
end 

當我把這個方法我收到以下錯誤:

Net::SMTPFatalError in Password resetsController#create 
555 5.5.2 Syntax error. 36sm970138yxh.13 

我發現一篇文章,說的問題是紅寶石1.8.4中的錯誤並且修復方法是從:from字段中刪除尖括號。果然,如果我只是使用「[email protected]」而不是「支持團隊<[email protected]>」,一切正常。

但是,在rails-2.3.5 API或ActionMailer Basics導軌指南中沒有提及此問題,實際上它們的actionmailer安裝示例中都顯示「名稱<郵件地址>」。任何人都知道我在做什麼錯了?

回答

0

軌道/的ActionMailer打破了這個:

https://rails.lighthouseapp.com/projects/8994/tickets/2340

既然這樣嚴重的安全漏洞沒有得到高優先級或臨時版本來解決他們在Rails項目,你要麼必須修補它自己或等待looong時間來修復它。就像這個在Rails 2.3.4中出現的瘋狂壞bug一樣,導致Ruby 1.9完全無法使用Rails:https://rails.lighthouseapp.com/projects/8994/tickets/3144-undefined-method-for-string-ror-234。花了幾個月的時間來解決這個問題。

3

從這個特拉維斯引用的票,它看起來好像你都不可能避免的問題:

def password_reset_instructions(user) 
    subject  "Password Reset Instructions" 
    from   "Support Team<[email protected]>" 
+ headers  "return-path" => '[email protected]' 
    recipients user.email 
    sent_on  Time.now 
    body   :edit_password_reset_url => 
        edit_password_reset_url(user.perishable_token) 
    end 

否則,您可以搶票注意到修補程序之一,或者等待2.3.6或3.x

+0

對不起,我以爲我已經迴應,但我沒有看到它在這裏。謝謝 - 你的解決方案就像一個魅力! – 2010-04-27 14:09:51

+0

看起來像他們在3月29日修補。 – iwasrobbed 2011-04-29 17:18:00

0

問題是從rails 2.3.4和2.3.5中使用的ActionMailer :: Base中的perform_delivery_smtp方法。你總是可以嘗試像這樣的猴子補丁:

class ApplicationMailer < ActionMailer::Base 

    def welcome_email(user) 
    recipients user.email from "Site Notifications<[email protected]>" 
    subject "Welcome!" 
    sent_on Time.now 
    ... 
    end 

    def perform_delivery_smtp(mail) 
    destinations = mail.destinations 
    mail.ready_to_send 
    sender = mail['return-path'] || mail.from 
    smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port]) 
    smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto) 
    smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password], 
       smtp_settings[:authentication]) do |smtp| 
     smtp.sendmail(mail.encoded, sender, destinations) 
    end 
    end 

end 
相關問題