验证与Ruby的电子邮件/密码组合

时间:2013-08-01 17:08:50

标签: ruby email email-verification

我正在编写一个Ruby(2.0)命令行应用程序,该应用程序涉及从用户提供的电子邮件/密码组合发送电子邮件。 (为了简化现在,我只使用Gmail帐户。) 通过使用Ruby的Mail gem,我很容易得到电子邮件发送。

每次发送电子邮件时,Mail gem似乎也可以检查用户电子邮件和密码的真实性。我坚持的是一种在不发送任何邮件的情况下验证电子邮件/密码的方法。

为了彻底,我已经包含了以下3次尝试的输出。没有用,我无法弄清楚我的错误在哪里。

这样做的成功方法是什么?


到目前为止的尝试......

首先我尝试使用Net :: SMTP:

> email = Net::SMTP.new('smtp.gmail.com', 587)
> email.start
> email.starttls
=> #<Net::SMTP::Response:0x007f9ff4133238 @status="220", @string="220 2.0.0 Ready to start TLS\n">

> email.auth_plain(email, password)
EOFError: end of file reached
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:153:in `read_nonblock'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:153:in `rbuf_fill'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:134:in `readuntil'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:144:in `readline'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:931:in `recv_response'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:925:in `get_response'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:737:in `block in auth_plain'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:941:in `critical'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:736:in `auth_plain'
from (irb):7
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<main>'

> email.auth_login(email, password)
NoMethodError: undefined method `success?' for "200 dummy reply code":String
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:961:in `check_auth_response'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:750:in `auth_login'
from (irb):8
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<main>'

接下来,我尝试使用Net :: POP3:

> email_pop = Net::POP3.new('pop.gmail.com', 995)
=> #<Net::POP3 pop.gmail.com:995 open=false> 
> email_pop.start('dtadams.testmail@gmail.com', 'testmail')
Net::ReadTimeout: Net::ReadTimeout
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:158:in `rescue in rbuf_fill'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:152:in `rbuf_fill'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:134:in `readuntil'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:144:in `readline'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:996:in `recv_response'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:893:in `block in initialize'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:1012:in `critical'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:893:in `initialize'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:562:in `new'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:562:in `do_start'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:536:in `start'
from (irb):17
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<main>'

...最后,使用Net :: IMAP尝试非常失败:

> imap = Net::IMAP.new('imap.gmail.com')
Errno::EHOSTUNREACH: No route to host - connect(2)
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/imap.rb:1045:in `initialize'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/imap.rb:1045:in `open'
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/imap.rb:1045:in `initialize'
from (irb):20:in `new'
from (irb):20
from /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<main>'

0 个答案:

没有答案