Hello all,
I'd like to process emails that I have in Outlook.
So far I dit this to test
LOCAL oOutlook, oNamespace, oFolder, oMailItem
oOutlook = CREATEOBJECT("Outlook.Application")
oNamespace = oOutlook.GetNameSpace("MAPI")
oFolder = oNamespace.GetDefaultFolder(6) && 6 for the reception box.
FOR EACH oMailItem IN oFolder.Items
If oMailItem.unRead
? oMailItem.Subject
? SUBSTR( oMailItem.Body, 1, 500)
? oMailItem.SenderName
? oMailItem.ReceivedTime
oMailItem.unRead = .F. && Mark it as read
Endif
ENDFOR
MESSAGEBOX("Finished")
This works. I thought it would give me emails in my default folder but no, it gives all email in my Office365 folder.
In outlook I changed the default folder, but still it's the emails that are in the office 365 folder that gets processed.
IF I change to this oFolder = oNamespace.GetDefaultFolder(1) I receive a bunch or effors
IF I change to this oFolder = oNamespace.GetDefaultFolder(2) I receive a bunch or errors
IF I change to this oFolder = oNamespace.GetDefaultFolder(3) It works a little bit but I also receive a bunch or effors
What is the meaning of the parameters in GetDefaultFolder()?
? SUBSTR( oMailItem.Body, 1, 500) I thought that I would receive only the content of the Body. but this gives me a lot more than I wanted. That's why I went for only a substring to see what's in there. Why so much informations? Any way to get only the content of the received email?
I'd prefer to process emails that are in another folder. Not the office365 folder. How can I specify in which folder I want to process the emails?
All help apreciated.
Is there a white paper or a class that could help me using Outlook in VFP?
Regards
What extra information are you seeing in your oMailItem.body? Is it formatting data (i.e. RTF)?
From my really old notes, these are predefined codes for commonly used folders:
- 1 - Outbox
- 2 - Sent Items
- 4 - Drafts
- 6 - Inbox
And from my really old, poor memory, play with these extra lines of code for ideas.
LOCAL oOutlook, oNamespace, oFolder, oMailItem, folderPath
* Prompt user for the folder path
folderPath = INPUTBOX("Enter the Outlook folder path (e.g., Inbox):")
' Create Outlook objects
oOutlook = CREATEOBJECT("Outlook.Application")
oNamespace = oOutlook.GetNameSpace("MAPI")
* Get the folder based on the provided path
oFolder = oNamespace.GetFolder(folderPath)
IF !oFolder.IsValid THEN
MESSAGEBOX("Invalid folder path!", MB_ICONSTOP)
ELSE
FOR EACH oMailItem IN oFolder.Items
IF oMailItem.unRead
? oMailItem.Subject
? SUBSTR( oMailItem.Body, 1, 500)
? oMailItem.SenderName
? oMailItem.ReceivedTime
oMailItem.unRead = .F. && Mark it as read
Endif
ENDFOR
MESSAGEBOX("Finished processing folder: " + folderPath)
ENDIF