2011-02-23 8 views
5

मुझे एक जीमेल खाता के माध्यम से एक मेलर भेज रहा है, और मैं यह जांचना चाहता हूं कि एक्शनमेलर वास्तव में जीमेल के एसएमटीपी सर्वर में लॉग इन कर सकता है जो मैंने दिया है। इसका परीक्षण करने का सबसे अच्छा तरीका क्या है?आप कैसे परीक्षण करते हैं कि रेल मेलर प्रमाण-पत्र मान्य हैं?

+0

आप परीक्षण करने की कोशिश कर रहे हैं? कि आपके क्रेडेंशियल्स सही हैं, या एक्शनमेलर वास्तव में काम करता है? –

+0

कि प्रमाण पत्र सही हैं। मेरा मानना ​​है कि एक्शनमेलर काम करता है। अगर मैं मैन्युअल रूप से पासवर्ड बदलता हूं लेकिन अपना कोड अपडेट करना भूल जाता हूं तो बस अपने परीक्षणों को पकड़ना चाहते हैं। – XZVASFD

उत्तर

9

यह एक पूर्ण-स्टैक समाधान नहीं है, लेकिन आप जांच सकते हैं कि सर्वर प्रमाणीकरण सीधे नेट :: एसएमटीपी का उपयोग कर सही ढंग से होता है। मेल मणि है कि 3 का उपयोग करता है रेल ActionMailer ईमेल भेजने के लिए तो जैसे मेल का उपयोग करता है (अपने ActionMailer.smtp_settings के साथ):

#line 96 of mail-2.2.7/lib/mail/network/delivery_methods/smtp.rb 
    smtp = Net::SMTP.new(settings[:address], settings[:port]) 
    if settings[:enable_starttls_auto] 
    smtp.enable_starttls_auto if smtp.respond_to?(:enable_starttls_auto) 
    end 

    smtp.start(settings[:domain], settings[:user_name], settings[:password], 
    settings[:authentication]) do |smtp| 
    smtp.sendmail(message, envelope_from, destinations) 
    # @Mason: this line need not be included in your code. SMTP#start throws 
    # a Net::SMTPAuthenticationError if the authentication was not successful. 
    # So just putting this call to #start with an empty block in a method and 
    # calling assert_no_raise Net::SMTPAuthenticationError should do the trick. 
    # The empty block is necessary so that the connection gets closed. 
    # Reference #{rubydir}/lib/ruby/1.8/net/smtp.rb for more info. 
    end 

ActionMailer तरह लग रहा है :: Base.smtp_settings भी पहुंचा जा सकता है:

settings = ActionMailer::Base.smtp_settings 

लाना कि आपके परीक्षण में और उपरोक्त बोली जाने वाली लाइन पर टिप्पणी करने के लिए आपके लिए एक कामकाजी उदाहरण होना चाहिए।

+0

कमाल। धन्यवाद टिम, और इसे आज़माने और स्वीकार करने के लिए बहुत लंबा समय लेने के लिए खेद है! – XZVASFD

5
smtp = Net::SMTP.new settings[:address], settings[:port] 
smtp.enable_starttls_auto if settings[:enable_starttls_auto] 
smtp.start(settings[:domain]) do 
    expect { 
    smtp.authenticate settings[:user_name], settings[:password], settings[:authentication] 
    }.to_not raise_error 
end 

कॉलिंग authenticate अगर प्रमाणीकरण विफल एक Net::SMTPAuthenticationError बढ़ा देंगे।

अन्यथा, यह Net::SMTP::Response लौटाएगा, और प्रतिक्रिया पर status पर कॉल करने से "235" वापस आ जाएगा।

+0

जहां तक ​​मुझे अपने स्वयं के परीक्षण में पता है, प्रमाणीकरण विफल होने पर 'प्रमाणीकरण' त्रुटि उत्पन्न नहीं करता है। यदि गलत पासवर्ड प्रदान किया जाता है, तो यह '.ring' में निम्न संदेश देता है, उदाहरण के लिए: '535 प्रमाणीकरण विफल: खराब उपयोगकर्ता नाम/पासवर्ड'। – theGreenCabbage

संबंधित मुद्दे