1 Replies - 2065 Views - Last Post: 26 November 2008 - 02:27 AM

#1 homemade-jam   User is offline

  • Gabe's Nemesis
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,300
  • Joined: 17-March 08

Check for new messages in outlook web access

Posted 11 August 2008 - 12:51 PM

Description: This is the first version of my first perl snippet that needs a couple of bits of tweeking...any comments are very welcome. I hope to add support for providing username and password as command line arguments. It requires the installation of a couple of cpan modules...http::mechanize and Stream::Reader for the file searchingIf your company email doesn't allow pop or imap access to your email then its very frustrating having to boot up your browser while all your other accounts can be checked easily from the comfort of thunderbird or outlook.
#!/usr/bin/perl 
use WWW::Mechanize;
use HTTP::Cookies; 
use Stream::Reader;
#use LWP::Debug qw(+); This was for development purposes

#now for the url to go to...
$url="https://mail.company.org.uk/exchange";
my $username = "username"; 
my $password = "password";
my $mechanize = WWW::Mechanize->new(autocheck => 1);
$mechanize->cookie_jar(HTTP::Cookies->new());
$mechanize->get($url);
$mechanize->form_name('logonForm');
$mechanize->field(username => $username);
$mechanize->field(password => $password);
$mechanize->click();

$mechanize->get("https://mail.company.org.uk/exchange/username/Inbox/?Cmd=contents&Page=1");

my $page = $mechanize->content();

#sleep 4;
#print $page;

open(FH, ">school.txt");
print FH $page;
close(FH);


my @substrings = (
'icon-msg-unread.gif'
);
my $handler;
open( $handler,'<','school.txt' ) or die; 
my $stream = Stream::Reader->new( $handler );
my $result = $stream->readto(@substrings, {Mode => 'E'}); #This mode returns false 
$emails = 1;

if( $result ) {
print ("You have new mail.n"); $emails++; 
} elsif( $stream->{Error} ) {
  die "Fatal error during reading file!n";
} else {
  print "No new messages.n";
}
unlink("school.txt");


Is This A Good Question/Topic? 0
  • +

Replies To: Check for new messages in outlook web access

#2 homemade-jam   User is offline

  • Gabe's Nemesis
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,300
  • Joined: 17-March 08

Re: Check for new messages in outlook web access

Posted 26 November 2008 - 02:27 AM

Am currently developing a version that will output sender, subject etc.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1