Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Import Email Messages Into Foxpro Table
Message
From
20/10/2000 11:45:41
 
 
To
18/10/2000 03:33:32
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00430762
Message ID:
00432102
Views:
18
Terry,

>What do I need to import outlook email messages into a foxpro table unattended.

Here's what I do with Outlook 98 to grab messages from a public folder (set up with MS Exchange Server), check the subject line and, if correct, store the message into a table, then archive the message out into another folder.

You could adapt this for your default inbox with the commented code included for that example.

Note that as I process each message (optionally storing it) and then archive each message, I must continually refer to the next one one as "...items(1)", since the messages move up in the inbox as each one is archived.

I took this approach of archiving immediately after processing each one, so that the program could just be restarted if it was interrupted for any reason, without the fear of reprocessing the same messages again.

This code was just quick and dirty, and could be further optimized, but I hope this helps point you in the right direction:
WAIT WINDOW NOWAIT "Starting up Outlook Email program"
ol=createobject("outlook.application")
ons=ol.getnamespace("MAPI")

* create table if necessary
* crea table bibmail (date D, mailtext M, processed L)

* set references to public folders
oAllPub=ons.folders("Public Folders").folders("All Public Folders")
oMain=oAllPub.folders("Admin Tasks").folders("Bibliofind")
oArchive=oAllPub.folders("Admin Tasks").folders("Bibliofind Archive")

* for default inbox, you could use:
* oInbox=ons.getdefaultfolder(6)

lncount=oMain.items.count

FOR lnLoop = 1 TO lnCount

  WAIT WINDOW NOWAIT "Processing Email Message # "+ ;
    ALLTRIM(STR(lnLoop))+ " of "+ALLTRIM(STR(lnCount))

  * reference this message
  oItem=oMain.items(1)

  * store contents, if subject is what we want
  IF ALLTRIM(oItem.Subject)=="Bibliofind want match"
      INSERT INTO bibmail ;
        VALUES ( DATE(), oItem.body, .f. )
  ENDIF

  oItem.move(oArchive)
  
ENDFOR

ons.Logoff

* some of these might not be necessary, but I didn't
* test for what happens to the other references when 
* "ons" and "ol" are killed
oArchive=NULL
oMain=NULL
oAllPub=NULL
oItem=NULL
ons=NULL
ol=NULL
WAIT CLEAR
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform