WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Delete Message from Exchange


Question:

I'm trying to create a simple script which will check an email box on an exchange server, read the subject, write the subject then delete the message off the server. I'm using the mapi extender wwmap34i. So far, I have everything working, except the deleting the email part. I cannot figure out how to delete the message after it is done.

I can log into the server. Massage the information, but do not see documentation on how to delete the message. I tried using postie, but it is not available as we do not allow pop/imap checking on the exchange server.

Answer:

;	I assume you want to delete mail in the INBOX...
;	try putting three emails into the INBOX and deleting them all.

objOutlook = ObjectOpen("Outlook.Application")
oln = objOutlook.GetNameSpace("MAPI")
oln.logon("", "", 0, 1)  ;userid/password combo...try it blank
;
;	Find the Mailbox Folder...
For x = 1 To oln.Folders.count  ;loop once for each folder
   If StrIndexNC(oln.Folders.item(x).name, "Mailbox -", 1, @FWDSCAN);< find user Mail Box
      Message("Debug", oln.Folders.item(x).name)
      MainFolder = oln.Folders.item(x).folders
      Inbox = MainFolder.item("Inbox") ;<-- Inbox
		break
	endif
Next
;
for x = 1 to Inbox.items.count  ;<-- loop thru the inbox's items...
	ThisMsg = Inbox.items(x)
	DaSubject = ThisMsg.subject
	DaBody    = ThisMsg.body
	DaTo      = ThisMsg.To
	DaSentBy  = ThisMsg.SenderName
	DaReceived= ThisMsg.ReceivedTime
	FileName  = strcat("c:\Email Message ", x, ".txt")  ;<-- you'll have to come up with something more elaborate...
	Filebody  = strcat("Sent By: ", DaSentBy, @crlf, "Received at: ", DaReceived, @crlf, "Sent To: ", DaTo, @crlf)
	Filebody  = strcat(Filebody, "Subject: ", DaSubject, @crlf, @crlf, DaBody)
	message("Item #%x%", Filebody)
	if askyesno("Outlook", "Delete this email?")
		ThisMsg.delete
		x = x - 1  ;must decrement loop because inbox count auto decrements...
;		fileput(FileName, Filebody)  ;<-- UNCOMMENT -- this may over write existing files...
	endif
next

;
message("Debug", "All Done")
;
MainFolder      = 0
Inbox           = 0
objOutlook      = 0
oln             = 0
;
Exit 

Article ID:   W17193
File Created: 2007:07:03:14:28:40
Last Updated: 2007:07:03:14:28:40