Problem connecting to hotmail using the pony gem

Hello,

I have only just started seariously playing with Ruby.
I have a script that needs to e-mail data it has gathered to a specific
address. I want to use my hotmail account to send out the e-mail until I
sort my own mail server, but can’t connect using pony.

my code is:

 Pony.mail(:to => "[email protected]", :from =>

[email protected]”, :via => :smtp,
:smtp => {:host => “smtp.live.com”, :port => “25”, :tls => true, :user
=> “fMyUserName”,
:password => “MyPassword”, :auth => :plain,
#:login, :cram_md5,
:domain => “localhost:chicken”}, :subject => “Optelec tweets”, :body =>
“This is a test”)

I am trying to send the email to myself to check if I can receive it.
Does it matter that the ‘from’ and ‘to’ addresses are the same.
When I run this (with the correct username and password) the connection
times out.
Uncommenting the commented line above gives errors when running, and I
think this line is actually gmail specific.

If there is a better way of doing this please let me know.

Regards,
Jen.

Hi Jen - Not too long ago I was involved w/ some code to do exactly this

  • connect to hotmail. Can’t say that I know the solution that my
    colleague developed before he left, but I do know that hotmail uses a
    fair amount of ajax (or whatever M$ calls it). That implies that it’s
    not as simple as sending an http request - there’s some processing on
    the login page that needs to happen first.

My next step in inheriting the work is to try to figure out how to parse
the javascript from ruby to send the proper request. Looking at either
the harmony or rkelly gems to do so. They might be suitable for what
you’re trying as well.

-Alex

Hi,

I found the ‘hotmailer’ gem, but when I try to use it I get an error
saying the “login” method is unknown. I’ve looked at the gem code and it
looks like I’m calling the correct method. Can someone please tell me
what I’m doing wrong :frowning:

Here is the code I used to test the gem:

 require "rubygems"
 require "hotmailer"
 #create object and login
 jen = Hotmailer.new("[email protected]","my_password")
 puts jen.inspect
 jen.login()

Here is the error I receive:

 /var/lib/gems/1.8/gems/hotmailer-1.0.1/lib/hotmailer.rb:24:in

login': undefined method login=’ for nil:NilClass (NoMethodError)
from hotmailertest.rb:6

The README for the hotmailer gem is located here:

File: README — Documentation for hotmailer (1.0.1)

Thanks in advance for any suggestions,
Jen.

On Sun, Sep 26, 2010 at 3:09 AM, Jen
[email protected]wrote:

require “hotmailer”

Hi Jen - Not too long ago I was involved w/ some code to do exactly this

sort my own mail server, but can’t connect using pony.
:domain => “localhost:chicken”}, :subject => “Optelec tweets”, :body =>

Honestly, I don’t think this hotmailer gem is going to work. Its last
release was December 2006. It also requires Mechanize, and Mechanize has
changed quite a bit since then. If you knew what version of mechanize it
wanted, you could download the correct version, but it doesn’t say, and
I
can see that some of its use is not correct any more. For example, the
class
is declared as “class Hotmailer < WWW::Mechanize” but using the WWW
namespace is deprecated.

Its initialize method is:

def initialize(username,passwd)
super()
self.user_agent_alias = “Windows IE 6”
@username = username
@passwd = passwd
@inbox = ‘’
@contacts = []
@messages = []
end

I don’t know if setting it to “Windows IE 6” is a problem or not, but it
seems quite improbable that you are using IE 6.

Here is where the problem you are running into is coming from:

def login
#Logs in the user
first_page = self.get(‘http://hotmail.com’)
login_form = first_page.form(‘f1’)
login_form.login = self.username
login_form.passwd = self.passwd

You see it gets the page at hotmail.com. Then it tries to fill out the
form
‘f1’. Looking at the hotmail page, it appears the form is still named
‘f1’,
but this method is returning nil (which is why login_form.login raises a
no
method error – because nil does not have a login method). I expect
that
this returns nil because you aren’t using the same version of Mechanize
as
this was written with.

Here are the versions of mechanize
All versions of mechanize | RubyGems.org | your community gem host You might scroll down to
find
the ones that were released prior to Dec 2006 (when the hotmailer gem
was
released). Then you can start installing old versions (gem install -v
0.6.3), and in the hotmailer gem, where it requires mechanize, tell it
which
one you want to use.

I’m not really sure how to tell it which one you want, I think you just
replace (require ‘mechanize’) with (gem ‘mechanize’, ‘=0.6.3’)

Anyway, if that still doesn’t work, theres only about 250 lines of code
in
that gem, you can possibly sit down with for a while and get it fixed.
Or,
find a gem that works better. This one manually logs into the site using
its
web interface. This is a fun idea, but will break any time hotmail
changes
anything your gem relies on. There are a number of gems related to
sending
email, and I know Rails just got a new one for Rails 3, probably your
best
bet will be to check one of them out.

Hi Josh,

I can’t see your message. Could you please send it again?

Thanks,
Jen.

On Wed, Sep 29, 2010 at 12:29 AM, Jen
[email protected]wrote:

Hi Josh,

I can’t see your message. Could you please send it again?

Thanks,
Jen.

Problem connecting to hotmail using the pony gem - Ruby - Ruby-Forum