Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting messages in sent items box in outlook with VFP

Status
Not open for further replies.

choppysuey

Technical User
Mar 28, 2001
54
US
Hi all...need help in figuring out the code to delete messages in the sent items box of MS outlook. I got a VFP program that emails out an attachment at certain times of the day. Everytime it emails a message a copy is sent to the sent items box. Anybody have code that will access the sent items box and delete those messages after the message has been sent? Thx in advance.

Here is the code I pieced together to generate the automatic email:

OFORM = CREATEOBJECT('FORM')
OFORM.ADDOBJECT('MAPISESS','OLECONTROL','MSMAPI.MAPISESSION')
OFORM.ADDOBJECT('MAPIMESS','OLECONTROL','MSMAPI.MAPIMESSAGES')
OFORM.MAPISESS.USERNAME = '....'
OFORM.MAPISESS.PASSWORD = '****'
OFORM.mapisess.signon

OFORM.mapimess.sessionID = OFORM.mapisess.sessionID
OFORM.mapimess.compose
OFORM.mapimess.msgsubject = "TEST message"
OFORM.mapimess.msgNoteText = "message note"

OFORM.mapimess.AttachmentIndex = 0
OFORM.mapimess.AttachmentName = "tmwrfdata.DAT"
OFORM.mapimess.AttachmentPathName = "c:\scada\SCADA.DAT"
OFORM.mapimess.AttachmentPosition = 0
OFORM.mapimess.AttachmentType = 0

OFORM.mapimess.RecipIndex = 0
OFORM.mapimess.RecipDisplayName = "Mark, Bowman"
OFORM.mapimess.RecipAddress = "SMTP:SCADA@ci.sparks.nv.us"
OFORM.mapimess.RecipType = 1

OFORM.mapimess.send(0)
OFORM.mapisess.signoff
 
Hi my friend
*// Creat object for OutLook application (Start)
myOlApp = CreateObject("Outlook.Application")
myNameSpace = myOlApp.GetNameSpace("MAPI")
*// Creat object for OutLook application (End )

*// Locate your SentItems folder as an object.(Start)
myFolder=myNameSpace.GetDefaultFolder(5)
*// Locate your SentItems folder as an object.(End )

*// Locate a Specific message.(Start)
FOR I= 1 to Myfolder.Items.Count
* You have to set you own selection criteria, for example
* I am locating a message from me with a certain subject.
*// Use OFORM.mapimess.msgsubject to find your message
*// If this is enough to identify this message
IF Myfolder.Items(I).Subject=OFORM.mapimess.msgsubject
OMyMessage=Myfolder.Items(I)
EXIT
ENDIF
ENDFOR
*// Locate a Specific message.(End )
IF TYPE('OMyMessage')='O'
OMyMessage.DELETE
ENDIF
myOlApp = .NULL.
myNameSpace = .NULL.
OMyMessage = .NULL.
myFolder = .NULL. Walid Magd
Engwam@Hotmail.com
 
Thx for the help Walid. The code works fine. Encoutered only one problem. It can't seem to delete the very first message in the sent items box. Every message being sent there after is being deleted. I tried changing the for loop to start at 0 instead of 1 and I get a array out of bounds error. I thought message one is at index 0. I will play with this for a bit. Thx again for the help.

 
Because the "Count" property decreases and the index on the entries change when you delete (or add) one, normally you'll want to process them in a loop that goes "backwards". i.e.:
FOR II = Myfolder.Items.Count TO 1 STEP -1

Rick


 
FWIW, if while iterating a collection/array, elements will be disgarded/deleted, it's best to use the FOR EACH command or count backwards per Rick's comments. FI:

FOR EACH oItem In MyFolder.Items
oItem.Delete
ENDFOR

Additionally, the FOR EACH command alleviates any possible confusion over whether the array is zero based (as in VB) or one based (as in VFP).

Walid,

If you would use the Find method of the Items collection, you could speed up your algorithm by reducing the amount of cross process calls. FI:

myOlApp = CreateObject("Outlook.Application")
myNameSpace = myOlApp.GetNameSpace("MAPI")
myFolder=myNameSpace.GetDefaultFolder(5)
OMyMessage=myFolder.Items.Find('[Subject]="Your subject"')

IF VARTYPE('OMyMessage')='O' && do not use TYPE() here
OMyMessage.DELETE
ENDIF Jon Hawkins

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
IF VARTYPE('OMyMessage')='O' && do not use TYPE() here
OMyMessage.DELETE
ENDIF


should read:

IF VARTYPE(OMyMessage)='O' && do not use TYPE() here
OMyMessage.DELETE
ENDIF Jon Hawkins

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Jon,
You are absolutely right about using FIND method, and this was my first attempt when I was developing this class, but at this time with that service back, my back bone, Spotnik 2005 or what ever name Microsoft want to call the bug fixing products, disappointedly enough it didn’t work with me, and I didn’t try it since then because the lack of time. I am sure all of us experienced this Microsofty frustration more than once. So I came up with this loop just to mimic this method.
I will try to assign some time to enhance this class if you give me your word that this method is working now. Thanks for you concern and valuable comments.
My best regards

Walid Magd
Engwam@Hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top