viewpoint-particle

Author Topic: Outlook Email Body Scrape  (Read 6389 times)

rickmds

  • Newbie
  • *
  • Posts: 39
Outlook Email Body Scrape
« on: March 04, 2014, 04:28:46 am »
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

  • Pundit
  • *****
  • Posts: 1939
    • Data & Stuff Inc.
Re: Outlook Email Body Scrape
« Reply #1 on: March 04, 2014, 05:19:08 am »
What you mean by using Outlook Rules?   Can you just check the account directly using POSTIE?

Jim

rickmds

  • Newbie
  • *
  • Posts: 39
Re: Outlook Email Body Scrape
« Reply #2 on: March 04, 2014, 07:09:08 am »
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

  • Pundit
  • *****
  • Posts: 1939
    • Data & Stuff Inc.
Re: Outlook Email Body Scrape
« Reply #3 on: March 04, 2014, 07:18:51 am »
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

  • Pundit
  • *****
  • Posts: 1939
    • Data & Stuff Inc.
Re: Outlook Email Body Scrape
« Reply #4 on: March 04, 2014, 07:22:58 am »
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

  • Newbie
  • *
  • Posts: 39
Re: Outlook Email Body Scrape
« Reply #5 on: March 04, 2014, 07:51:46 am »
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

  • Pundit
  • *****
  • Posts: 1939
    • Data & Stuff Inc.
Re: Outlook Email Body Scrape
« Reply #6 on: March 04, 2014, 08:35:10 am »
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

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Outlook Email Body Scrape
« Reply #7 on: March 04, 2014, 08:50:19 am »
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
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

  • Newbie
  • *
  • Posts: 39
Re: Outlook Email Body Scrape
« Reply #8 on: March 04, 2014, 11:42:43 am »
Jim
I very much appreciate your help and suggestions.

Deana
Thank you for this snippet!

....IFICantBYTE

  • Full Member
  • ***
  • Posts: 125
Re: Outlook Email Body Scrape
« Reply #9 on: March 04, 2014, 04:15:43 pm »
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

  • Newbie
  • *
  • Posts: 39
Re: Outlook Email Body Scrape
« Reply #10 on: March 05, 2014, 03:40:24 am »
IFICantBYTE
Thank you for this information; I will check it out!