Hello.
>> We receive emails from our website each day from potential customers. The email is sent to our mailbox with 10 questions answered (Last name, first name, address, etc).
The format is exactly the same, it comes from the same email address with the same subject each time.
What I want to do is save the body of the message as a text file so I can import into tables. <<
You can do this using MAPI. However, because of the Draconian Security Patch from H*ll, you will also need to use something like Express Click Yes (
) to suppress the messagebox that pops up to warn you that something is trying to access your inbox. The program is free and it comes with VFP sample code.
You can create a mapi class using a container and dropping 2 ActiveX container controls into it. One will hold the mapi messages control (called oMessage) and the other will hold the mapi session control (called oSession). You can then use sample code like this to get started:
First you need to create a MAPI session:
Code:
LPARAMETERS tcUserName, tcPassword
WITH THIS.oSession
*** Save the current directory because the following code will change it
lcCurDir = FULLPATH( CURDIR() )
*** Go ahead and set the properties and sign on
.UserName = tcUserName
.Password = tcPassword
.DownloadMail = .T.
*** And sign on
.SignOn()
ENDWITH
*** Change back to default directory
SET DEFAULT TO ( lcCurDir )
Next, you need to read the messages. Code like this:
Code:
lcSender = 'someone@somedomain.com'
lcSubject = 'something i am interested in'
WITH THIS.oMessage
.SessionID = This.oSession.SessionID
.FetchUnreadOnly = .T.
.Fetch()
FOR lnMsg = 1 TO .MsgCount
*** The Message Index is 0-based, so adjust
.MsgIndex = lnMsg - 1
IF ( lcSender $ LOWER( .MsgOrigDisplayName ) OR lcSender $ LOWER( .MsgOrigAddress ) ) AND ( lcSubject == ALLTRIM( LOWER( .MsgSubject ) ) )
*** Process the body of the message here
lcText = .MsgNoteText
*** Now use STRTOFILE to save the message as
*** a text file or just insert it into a memo
*** field in a table or whatever processing you
*** need to do
ENDIF
ENDFOR
ENDWITH
Marcia G. Akins