Net::POP3 and Firewall

Hi,
I’m trying to use Net::POP3 from behind a firewall and I can’t get past
this error
C:/ruby/lib/ruby/1.8/net/protocol.rb:206:in `initialize’: Bad file
descriptor - connect(2) (Errno::EBADF)

I had a similar error when trying to access a url via http but I got
around it by using a Net::HTTP::Proxy i.e.

host = 'whatever ’
path = ‘/…/ etc’

proxy_addr = ‘my.proxy.addr’
proxy_port = myProxyPort

response = Net::HTTP::Proxy(proxy_addr, proxy_port).get_response(host,
path)
puts response

I’ve been unable to find anything similar for Net::POP3 ie code like
this

pop = Net::POP3.new(…)

just dies and gives the error at the start of this post.

What do I need to do? Are there some ENV vars that need setting? I’ve
spent a day Googling etc. but go nowhere!

Thanks

Mike

This code woks on my home PC - i.e. no firewall. Does anyone know what’s
needed for it to run from behind a firewall?
###############
require ‘net/pop’

pop = Net::POP3.new(‘pop.mail.yahoo.co.uk’, 110, false)
pop.start(‘myUserName’, ‘myPwd’)
if pop.mails.empty?
puts ‘No mail.’
else
i = 0
pop.each_mail do |m|
File.open(“inbox/#{i}”, ‘w’) do |f|

      f.write m.pop
    end


    i += 1
  end
  puts "#{pop.mails.size} mails popped."
end
pop.finish

#################

I’d really appreciate any thoughts or comments.

Thanks

Mike

On Wed, Oct 03, 2007 at 02:50:19AM +0900, Mike Ho wrote:

else
  puts "#{pop.mails.size} mails popped."
end
pop.finish

#################

I’d really appreciate any thoughts or comments.

I don’t know of any programmatic way to do this - have you spoken to
your
firewall administrator? He will need to allow POP3 traffic out to the
Internet (at least from the box hosting your app to the POP3 server it
is
trying to contact) and back again.

You could also check out SOCKS, which may enable you to proxy through
the firewall.

Dan

Hello,

I am troubling wit fetching my .xls attachments from my mail.i did
this with the help if IMAP.but i wan to do the same in using POP3.i got
the text files with the contents and some of bar codes.but i couldn’t
get the original attachments from my mail.Plz help me.Thanks in
advance.my code is.

require 'rubygems'
require 'net/pop'


Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
pop = Net::POP3.new('pop.gmail.com',  Net::POP3.default_pop3s_port, 

false)
pop.start(‘[email protected]’, ‘password’)
if pop.mails.empty?
puts ‘No mail.’
else
i = 0
pop.each_mail do |m|
File.open(“inbox/#{i}”, ‘w’) do |f|
f.write m.pop
end
i += 1
end
puts “#{pop.mails.size} mails popped.”
end
pop.finish

###############
File.open(“inbox/#{i}”, ‘w’) do |f|

                                     - against HTML, vCards and  X
                            - proprietary attachments in 

e-mail / \

One faily cheap and easy trick - if the requirements are met - is
tunneling
over SSH. If the firewall allows SSH traffic to the internet, and if you
have a machine outside the firewall that you can SSH to, you can ‘proxy’
your POP3 like so:

ssh -L5000:ip.of.mail.server:110 [email protected]

And then connect to localhost:5000 to retrieve mail.

You could probably also utilize net/ssh as a ruby library to build the
tunnel within the script, though I’ve never done that.

If this is in a corporate (or other network policy) situation, note that
any circumvention of the firewall will be very, very frowned upon and
may
lead to termination - always check with the policy makers first.

HTH,

Felix