Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^2: is it possible to use Perl to process Outlook emails?

by mertserger (Curate)
on Jul 26, 2011 at 13:22 UTC ( #916766=note: print w/replies, xml ) Need Help??

in reply to Re: is it possible to use Perl to process Outlook emails?
in thread is it possible to use Perl to process Outlook emails?

The plan is for the data to arrive in an Outlook mailbox, in the normal work email system (which is an Exchange server). I have experimented with using the Outlook in-built export functionality to get the data into Access but the entire email body ends up as a single field.

As they say I wouldn't have started here but that part of the system was agreed between the corporate IT department and the users before I got involved.

  • Comment on Re^2: is it possible to use Perl to process Outlook emails?

Replies are listed 'Best First'.
Re^3: is it possible to use Perl to process Outlook emails?
by cjb (Friar) on Jul 26, 2011 at 14:08 UTC
    Your exchnage sever may have POP3 mail box access set up. If it has it's fairly easy to get Mail::POP3Client to grab the mail. I've had to do this recently:
    #!c:\strawberry\perl\bin\perl.exe use Modern::Perl; use Mail::POP3Client; use MIME::QuotedPrint; my $pop_user = 'XXXXXXXXXX'; my $pop_pass = 'XXXXXXXXXX'; my $pop_host = 'exchange3'; #connect to POP3 sever my $pop = new Mail::POP3Client ( HOST => $pop_host ); $pop->User($pop_user); $pop->Pass($pop_pass); $pop->Connect() or die "Unable to connect to POP3 server: ".$pop->Message()."\n"; #count number of items in POP3 mailbox my $mailcount = $pop->Count(); for (my $i = 1; $i <= $mailcount ; $i++) { my $header = $pop->Head($i); #gets the header my $uni = $pop->Uidl($i); # gets the unquie id my $body = $pop->Body($i); $body = decode_qp($body); #decode quoted printable body say "$uni"; say "$header\n"; say "$body"; }
    Edit 27/07/2011@10:33BST Removed reference to subroutine not include in code &return_error and replaced with die
      I tried to run this routine. The error message was: "unable to connect to POP3 server: couldn't connect socket exchange3, 110; Invalid argument." Any advise will be appreciated. Thanks in advance.
        So you don't have a server named "exchange" ... what is the name of your server?
Re^3: is it possible to use Perl to process Outlook emails?
by ~~David~~ (Hermit) on Jul 26, 2011 at 18:05 UTC
    Well, if you want a really backwards way to do it ( which is how I do it! ), i do it like the following:
    1. Set up a complex rule in Outlook so that when a message arrives, the following sequence occurs:
    a) Outlook can start up a program for you in the rule, i use it to start my perl program, which waits for:
    b) Run the following VB script to save the email to a local file, which your perl script is polling
    Sub WriteEmailToFile(MyMail As MailItem) Dim myMailEntryID As String Dim myMailBody As String Dim outlookNameSpace As Outlook.NameSpace Dim outlookMail As Outlook.MailItem myMailEntryID = MyMail.EntryID Set outlookNameSpace = Application.GetNamespace("MAPI") Set outlookMail = outlookNameSpace.GetItemFromID(myMailEntryID) Set fileSystemObject = CreateObject("Scripting.FileSystemObject") / you can create a dynamic text file name is you want... Set textFile = fileSystemObject.CreateTextFile("c:\temp\OutlookEma +il.txt", True) textFile.WriteLine (outlookMail.SenderEmailAddress) textFile.WriteLine (outlookMail.SentOn) textFile.WriteLine (outlookMail.Subject) outlookMailBody = outlookMail.Body 'strip non-printing characters For x = 127 To 255 While InStr(outlookMailBody, Chr(x)) > 0 outlookMailBody = Replace(outlookMailBody, Chr(x), "") Wend Next x textFile.WriteLine (outlookMailBody) textFile.Close End Sub

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://916766]
[ambrus]: Now it has five people instead of three, some sort of call number ticket system where people wait a lot for their food to get ready (it's the same kinds of grilled meat and fish on the same equipment, it won't actually fry slower),
[ambrus]: it's slow as hell, and the food costs significantly more.
[ambrus]: We no longer eat there.
LanX Everybody quotes it, some people read it, and a few people go by it
[ambrus]: LanX: why would I read it? isn't it a book for managers? I don't want to be a manager.
[ambrus]: I don't quote it either.
[erix]: it's really a software book, albeit about experiences from the 60s-80s. People haven't changed all that much though.
[erix]: a software project book, is probably more exact
[ambrus]: Yes, but I'm not managing software teams either.
[ambrus]: I'm not only not a restaurant manager, but also not a software manager.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2017-09-22 13:55 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (264 votes). Check out past polls.