Board index » delphi » deleting unwanted Outlook messages
|
Kerry Frater
Delphi Developer |
deleting unwanted Outlook messages2003-10-26 06:30:45 PM delphi5 I am trying to write a routine to extract mailmessages that I want and deleting unwanted unread messages. The routine (so far) is shown below. The key part of the deletion (as far as I can tell) is ThisMsg.Delete; But when the function runs I get the runtime message "The item has been moved or deleted" as a dialog box. Only the one message. When I look at the messages with Outlook, nothing has changed. Can anyone give me some advice please. Kerry This is the code run earlier on to open up the link to Inbox with the TOutlookApplication component OA1.Connect; nmSpace := OA1.GetNamespace('MAPI'); nmSpace.Logon('','',False,False); MyInbox := nmSpace.GetDefaultFolder(olFolderInbox); procedure TFmMailProcess.DoProcessing; var i,MyCount: integer; MyTime: TTime; MyMatter,MyRef: string; MyFile: WideString; ThisMsg: MailItem; begin ProcessingMail := -1; MyKnown := 0;MyUnKnown := 0; if assigned(MyInbox) then begin EdUnreadMessages.Text := IntToStr(MyInbox.UnReadItemCount); MyMsgItems := MyInbox.Items; if MyMsgItems.Count>0 then begin MyCount := 1; for i := 1 to MyMsgItems.Count do begin if MyMsgItems.Item(i).QueryInterface(MailItem,ThisMsg) = s_OK then begin ThisMsg := MyMsgItems.Item(i) as MailItem; if ThisMsg.UnRead then begin MyInfo := copy(ThisMsg.Subject,1,5); if TblMyInfo.Locate('MyRef',MyInfo,[]) then begin MyKnown := MyKnown + 1; ProcessMessage(ThisMsg); end else begin MyUnknown := MyUnknown + 1; ThisMsg.Delete; {This is the key line that doesn't work} end; MyCount := MyCount + 1; end; end; end; EdKnown.Text := IntToStr(MyKnown); EdUnKnown.Text := IntToStr(MyUnknown); end; end; ProcessingMail := 0; end; |
