Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Hotmail Login/Forwarding Script

by Anonymous Monk
on Aug 30, 2004 at 20:03 UTC ( #387017=sourcecode: print w/replies, xml ) Need Help??
Author/Contact Info
Description: this script will login to hotmail and forward all messages that are unread to whatever email address you want. you need to set your options in hotmail to the advanced view so that there is a link to view the email source. the script requires sendmail so its probably best to run it from a *nix box (i have it run as a cron job every 30 minutes). this also requires the LWP bundle as well as the Crypto::SSLeay module (for the https). You could set it up to use Sockets to talk to the mail server directly and lots of servers are picky about who they allow (i tried but it messed up sometimes). Any improvements are welcome and i hope this helps some people.

$user = 'username';        # hotmail user name
$pass = 'password';        # hotmail password
$addr = '';    # forwarding address
$delay = 30;            # delay (in seconds) between sending messages
$delete_messages = 0;        # 0/1 => don't/do delete messages from th
+e hotmail account

require LWP::UserAgent;
require HTTP::Cookies;

# set up our super cool web browser
$ua = LWP::UserAgent->new;
push @{$ua->requests_redirectable}, 'POST';
$ua->agent("yellow rubber ducky");

# let's get some "hot" mail
$html = $ua->get('')->content;

# we don't need no stinkin' javascript
while( $html =~ s/<input type=hidden name="([^"]*)" value="([^"]*)">//
+ ){
    $form{$1} = $2;
$html = $ua->post( '', \%for

# log on in
$html =~ /<form TARGET="_top" name="hotmail_com" action="([^"]*)"/;
$html = $ua->post( $1, ['login'         => $user,
                        'passwd'        => $pass,
                        'domain'        => '',
                        'sec'           => '',
                        'mspp_shared'   => '',
                        'padding'       => substr( "xxxxxxxxxxxxxxxx",
+0, 16-length($pass))])->content;

# follow the magic meta
$html =~ /<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=([^"]*)"/;
$html = $ua->get($1)->content;

# we definetly don't need no stinking internet explorer
$html =~ /<form name="cont" action="([^"]*)"/;
$html = $ua->post( $1, ['curmbox'       => 'F000000001', 
                        'HrsTest'       => ''])->content;
$base = $1;
$base =~ s/\/cgi-bin\/.*//;

# find out where we can get our free massages
$html =~ /_UM = "([^"]*)"/;
$UM = $1;
while( $html =~ s/<a href="javascript:G\('(\/cgi-bin\/getmsg?[^']*)'//
+ ){
    if( $1 !~ /msgread/ ){
        push @messes, $1;

# get the whole mess
foreach $mess(@messes){
    $html = $ua->get($base.$mess."&".$UM)->content;

    # junk it
    if( $delete_messages ){
        $html =~ /<a href="#" onclick="G\('([^']*)'.*>Delete<\/a>/;
    # go straight to the source (set the options for advanced view)
    $html =~ /<a href="([^"]*)" target="_blank">View E-mail Message So
    $html = $ua->get($1)->content;
    $html =~ /<A HREF="([^"]*)">here<\/A>/;
    $html = $ua->get($1)->content;

    # clean up the mess
    $html =~ s/<pre>\s*([\w\W]*)<\/pre>[\w\W]*/$1/;
    $html =~ s/&quot;/"/gi;
    $html =~ s/&lt;/</gi;
    $html =~ s/&gt;/>/gi;
    $html =~ s/&amp;/&/gi;
    $html =~ s/\n\.\n/\n .\n/g;
    $html =~ s/(\s+)To:.*/$1To: $addr/;

    open MAIL, "|/usr/sbin/sendmail -t";
    print MAIL $html;
    close MAIL;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://387017]
and nobody stirs...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2017-05-29 17:18 GMT
Find Nodes?
    Voting Booth?