Nalina has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

How to extract a newly arrived mail from MS outlook? I tried using Mail::pop3Client module to connect, but did not work. The script is as follows
use Mail::POP3Client; $pop2 = new Mail::POP3Client( HOST => "xxx.xxx.xxx.xxx" ); $pop2->User( "user" ); $pop2->Pass( "pass" ); $pop2->Connect() >= 0 || die $pop2->Message(); $pop2->Alive; $pop2->Close();
The host here is the IP of the pc or the mail server?

Should the user id be mentioned with domain like 'user@doman.com' or just the user name like 'user'?

Replies are listed 'Best First'.
Re: Read new mails in MS Outlook
by Crackers2 (Parson) on Aug 16, 2004 at 14:33 UTC

    If you have your outlook set up like most people, what you want is not going to work, at least not with that module.

    When outlook retrieves the mail from the mail server, it will delete it from the server. Which means it will not be accessible there anymore if you try to get it through perl or any other client from that server. (I'm assuming here of course that your mail server is a POP server, and not IMAP or Exchange.

    Since the mail is already in outlook, you should probably look at some of the modules that interact directly with it. Look in the Win32::OLE family of modules

    Another possible approach, but somewhat fragile, is to set up outlook to not delete the mails from the server, and then have your script delete them after retrieval. Of course that means you run the risk of having your script delete the mails before outlook got to them

      I am trying to read all mails in inbox of MS Outlook. The script is
      use Win32::OLE; #use Win32::GuiTest; use Win32::Clipboard; $OL = Win32::OLE->GetActiveObject('Outlook.Application'); $NameSpace = $OL->GetNameSpace("MAPI"); $Inbox = $NameSpace->GetDefaultFolder(6); #-- inbox folder $Deleted = $NameSpace->GetDefaultFolder(3); #-- deleted it +ems folder $Root = $Inbox->Parent(); $MyAccount = $Root->Folders("Inbox"); $MyAccountOK = $MyAccount->Folders("Filtered"); $Clip = Win32::Clipboard(); #$Clip->Empty(); $cnt=$MyAccount->Items->Count; print "count = $cnt"; while ($cnt > 0) { $Clip->Empty(); #-- empty the clipboard #$MyAccount->Items($cnt)->Display; #-- display/open me +ssage with index of $cnt in the MyAccount folder undef $text; $text=$Clip->Get(); #-- get clipboard contents #print "text = $text\n"; $text=~tr/A-Za-z.@/*/c; #-- convert all but listed valid + characters to * $text=~tr/*//d; #-- now delete asterisks $text=lc($text); #-- convert to lowercase # -- now check for our email address in the internet heade +r text if ($text !~ /myaccount\@yahoo\.com/) { print "No\t"; #-- move message to De +leted Items folder } else { print "Yes\n"; $MyAccount->Items($cnt)->Move($MyAccountOK); #-- m +ove message to MyAccount->Filtered folder } $cnt--; }
      But $text is empty. Clipboard does not has anything( $text=$Clip->Get();). Please help me.
      Could u please tell me how to use Win32::OLE module to extract new mails.
        I'm afraid I won't be able to help you here. I've only read about the Win32::OLE modules and have never used them myself (I do all my perl programming on linux)
Re: Read new mails in MS Outlook
by rupesh (Hermit) on Aug 16, 2004 at 12:46 UTC

    The host here is the IP of the pc or the mail server
    It should basically be the IP of the mail server

    Should the user id be mentioned with domain like 'user@doman.com' or just the user name like 'user'
    As long as you are in windows, it is better if you mention the user as <domain name>\<user name>

    Update: More info on the parameters
Re: Read new mails in MS Outlook
by keszler (Priest) on Aug 16, 2004 at 15:21 UTC
    Assuming that you're getting the email from an MSexchange server, you'll likely be needing Convert::TNEF (also available with Activestate's ppm). When POPping email from MSexchange you'll often find that an email consists solely of a "winmail.dat" attachment in TNEF format, containing the plain text, "rich" text, and/or MIME attachments of the original email.

    The "rather long" POP3 example in the Convert::TNEF documentation should give you a good start.