Hotmailer Library v0.1

The hotmailer library is used to programatically access your hotmail account. It depends on the ‘mechanize’ (and by extension ‘hpricot’) libraries.

The Hotmailer library contains two objects:

  1. WWW::Hotmailer - this is descended from WWW::Mechanize, but has been specialised for hotmail.

  2. Hotmailer::Message - This is the class for hotmail messages.

WWW::Hotmailer

This contains the following methods.

  • new(username,password) - Used for creating a new hotmailer object. Note that this will not login for you, but only initialize the object.

eg. zaphod = Hotmailer.new(‘[email protected]’,‘chunkybacon’)

  • login - This logs in a hotmailer object to hotmail.

eg. zaphod.login

  • contacts(reload=false) : this gets a list of your hotmail contacts, in the form of a list of hashes, each hash containing a :name, and an :email for that contact. The first time it gets the contacts it caches them to save time - passing reload=true to the function forces it to reload the contacts from hotmail.

eg. contacts = zaphod.contacts

contacts is now [=> “Ford Prefect”,:email => “[email protected]”,=> “Trishia Macmillan”,:email => “[email protected]”]

  • compose(to,subject,body) : This sends an email to the ‘to’ address, using subject and body.

  • messages(reload=false) : This gets all the messages in your hotmail inbox. It returns an array of Hotmailer::Message objects. The first time it gets them it caches them and returns this cache on subsequent calls, unless you specify reload=true.

eg. messages = zaphod.messages(true)

  • add_contact(quickname,email,fname=”,lname=”) : This adds a contact to your hotmail address book. Only quickname and email are obligatory - fname (First Name) and lname (Last Name) can be left blank.

eg. zaphod.add_contact(‘barty’,‘[email protected]’,‘Slarti’,‘Bartfast’)

Any of these methods will raise an error if there is a problem - you therefore should capture these errors in your program if you want to recover from them somehow.

Hotmailer::Message

This is the hotmail message class, and it contains the following (read only) attributes:

  • from_email : The sender’s email address.

  • from_name : The sender’s name.

  • status : One of “Read”, “Unread”, and “Forwarded”, describing the status of the message

  • subject : The subject of the message

  • date : The date it was sent

  • size - The message’s size (eg. ‘4 KB’)

  • body - The text of the message (in plain text)

In addition the following methods are also available:

  • read : This returns the body of the message (in plain text). This is the same as the body attribute.

  • delete : This deletes the message from the user’s inbox, and places it in trash (where it will automatically disappear into the great void after a few days).

  • forward(to) - This forwards a message to the to email address specified.

Example Run

require ‘hotmailer’

#Create object and login zaphod = Hotmailer.new(‘[email protected]’,‘chunkybacon’) zaphod.login

#Get messages messages = zaphod.messages

#Get details of first message puts messages.from_email puts messages.from_name puts messages.subject puts messages.body

#Forward first message to Arhur messages.forward(‘[email protected]’)

#Delete first message messages.delete

#Add Arthur’s contact details zaphod.add_contact(‘arthur’,‘[email protected]’,‘Arthur’,‘Dent’)

#Get contacts list contacts = zaphod.contacts