Outlook Email Body Scrape

Started by rickmds, March 04, 2014, 04:28:46 AM

Previous topic - Next topic

rickmds

I am looking to use Outlook rules to trigger an application from an incoming email.  The body of the outlook email would be plain text and contain several parameters on separate lines, e.g., Date: 02/17/2014, Report: Personnel, Directory: C:\Reports\HR etc. that would be used in calling of the application.  My questionââ,¬Â¦ any recommendations on how to best scrape these parameters out of the Outlook email body to use them in the calling of the application?  Thanks in advance for any suggestions you may have.

JTaylor

What you mean by using Outlook Rules?   Can you just check the account directly using POSTIE?

Jim

rickmds

Jim
Please see attached image of executing the rules feature in Outlook.  Thanks for the suggestion but the solution needs to use Outlook.
Rick

JTaylor

Didn't ask the question very well...I know what Outlook Rules are...I meant more along the lines of what criteria.   I have (not using presently) an application that does a similar thing but I checked the account using postie and checked my list of "rules" in the email that I retrieved.   I assume one can retrieve rules using COM but not sure.

Jim

JTaylor

If your rules put such emails in a particular mailbox you could easily pull all the needed emails from there and not have to worry about reading your rules.

Jim

rickmds

Here is a bit more background.  I am currently using Postie to push the distribution of scheduled reports to the client now.  They are currently using Outlook, provided us with an Outlook email account  and would now like us to give them the opportunity to ââ,¬Å"pullââ,¬Â reports based on criteria that they can select; we have done this with an email form.  After completing the form they will email it to the assigned email account.  Once the email arrives an Outlook rule is applied, to read the ââ,¬Å"subjectââ,¬Â of the email and process the request based on the criteria the client has provided. 

My original request still appliesââ,¬Â¦ I am looking for a recommended approach from the group on the best way to read the report parameters from the body of the Outlook email.  Once the Outlook email body is in a text file I can manipulate it accordingly using, WinBatch process the request and email the reports... probably using POSTIE.

JTaylor

Sorry if I am being dense and annoying....it sounds like you don't need to read rules or sort through other emails and such so....is the question how to get the text of the email itself?

If so, I would recommend using the MAPI extender to read the messages if you aren't allowed to use POSTIE and SMTP to read from that account.

Jim

Deana

Outlook acts as a COM/OLE Server that exposes its mailitem objects. However much of the built-in security in current versions of outlook severely limit the types of operations that are allowed.

Here is a link the OLE and Outlook section in our tech database:
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/OLE~and~Outlook

Code sample to help get you started: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/OLE~and~Outlook+OLE~and~OUTLOOK~read~mail~other~than~inbox.txt

Code (winbatch) Select
olFolder="Personal Folders"  ;Top level Folder name
myFolder="Junk" ;(case sensitive) change this to the folder you want
objOutlook = ObjectCreate ("Outlook.Application")
objNameSpace = objOutlook.GetNamespace("MAPI")
objFolder1 = objNameSpace.Folders(olFolder);
objFolder=objFolder1.Folders(myFolder);
objcount=objFolder.Items
mycount=objcount.Count ;checks number of messages
For xx = 1 to mycount
  objitem=objFolder.Items(xx)
  myText = objitem.Body
  message(" %MyFolder% Message Body #%xx%",mytext)
Next
objOutlook = 0
exit


If you run into security issues see Redemption: http://www.dimastr.com/redemption/home.htm
Deana F.
Technical Support
Wilson WindowWare Inc.

rickmds

Jim
I very much appreciate your help and suggestions.

Deana
Thank you for this snippet!

....IFICantBYTE

Similar to what Jim was alluding to....
To get around the issues with using Outlook on the "back-end" at all (No Outlook server side vs. client side rules processing needed, no Outlook/security/redemption issues etc.)

... if, as you say, they have provided you with an email account, then it is probably hosted on a local Exchange server. If so, then you should be able to talk to it with clients other than Outlook.
That way, you don't have to use Outlook to see, read, and process the returned emails at all.
Only the users who are sending you the requests and receiving the results would continue to use Outlook as they normally would for all their email including this stuff.

Depending on what the Exchange server makes available to you, you could use POP or IMAP (postie can do that) to talk directly with that account.

Also, for more granular IMAP needs, if you have a newish version of WinBatch that supports CLR/.Net stuff, you can use some good 3rd party IMAP components (I have recently done something similar with an Avaya voicemail server using https://mailsystem.codeplex.com/). Deana was very helpful in providing me with the beginnings of the .NET handling I needed... there are a couple of examples in the Tech Database.
Regards,
....IFICantBYTE

Nothing sucks more than that moment during an argument when you realize you're wrong. :)

rickmds

IFICantBYTE
Thank you for this information; I will check it out!