To read e-mail into OpenInsight, perform the following steps:
Logon to the MAPI server, using MAPILogon().
Retrieve the list of mail IDs, using MAPIOpenMail().
Loop through the list, using MAPIReadMail() to read each message, processing as required.
When done, logoff the MAPI server, using MAPILogoff().
Note: Simple MAPI supports only reading from the inbox. Reading from email folders is not supported.
Note: Useful flags when reading messages are:
MAPI_ENVELOPE_ONLY$ - read only the header, not the message text and file attachments
MAPI_SUPPRESS_ATTACH$ - don't read the file attachments
MAPI_BODY_AS_FILE$ - return the message text as the first file attachment, instead of including the message in the message structure
MAPI_PEEK$ - do not mark the message as read.
The code below reads the inbox, stores the contents of the email in a table called REVDATA, and deletes the email from the inbox. The Msg() function, with the GC parameter, displays a gas gauge type message as the mail is being read and processed. It is removed after processing has completed.
* Reads e-mail from your inbox and places them in a file called REVMAIL $Insert MAPI_EQUATES $Insert MSG_EQUATES Declare Subroutine Get_Status Declare Function MAPILogon, MAPILogoff, MAPIOpenMail, MAPIReadMail, Msg, Set_Property Declare Function MAPIDeleteMail Open "REVMAIL" to DataFile then If MAPILogon(MapiSession, 0,"","", MAPI_LOGON_UI$ + MAPI_NEW_SESSION$+ MAPI_FORCE_DOWNLOAD$) Then Flags = MAPI_PEEK$ + MAPI_GUARANTEE_FIFO$ if MAPIOpenMail(MAPIsession, 0, "IPM.", Flags, ids) then Flags = MAPI_PEEK$ Def = "" Def<MCAPTION$> = "Fetching New Messages" Def<MTYPE$ > = "GC" Def<MEXTENT$ > = Count(IDS,@FM) + Len(IDS[1,1]) YOURTEXT = '%' Def<MTEXT$> = YOURTEXT Def<MTEXTWIDTH$> = 100 * Display a message with gasguage MsgUp = Msg(@window, Def) TotRecs = Count(IDS,@FM) + Len(Ids[1,1]) Cnt = 0 For x = 1 to TotRecs If MAPIReadMail(MapiSession, @WINDOW, Ids<x>, Flags , Message) then Rec = "INBOX" Rec<2> = ICONV(Message<POS_DATE$>[1,10],"DE") Rec<3> = ICONV(Message<POS_DATE$>[11,5],"MT") Rec<4> = "" Rec<6> = Message<POS_FROM$> Rec<7> = Message<POS_TO$> Rec<8> = Message<POS_CC$> Rec<9> = Message<POS_BCC$> Rec<10> = Message<POS_SUBJECT$> Rec<11> = '' Rec<12> = Message<POS_TEXT$> Convert Char(13):Char(10) to @TM in Rec Write Rec on DataFile, Ids<x> Then * Delete message from the MAPI message store status = MAPIDeleteMail(MAPISession, @Window, Ids<x>) End End * Update the Message with the percentage of e-mails imported YOURVAR = int(x/TotRecs*100) : YOURTEXT Val = SET_PROPERTY('MSG.ST_TEXT','TEXT',YOURVAR) While Msg(@window, MsgUp, x, MSGINSTUPDATE$, '') Next x End Val = MAPILogOff(MapiSession) End End