Forum Discussion
Permanently delete junk mail that has certain subject words
- Lorne54Nov 27, 2023Copper Contributor
Thanks for that. It probably does the trick but I decided to write my own code that I have copied below if anybody is interested. I wrote it in Delphi but the code is readable so anybody knowing C++ or other languages can probably work out what it is doing. An interesting fact is that I found out that all the junk I did not want to check could be deleted just by looking at the sender's email which was always blank ! This code comes with no guarantees so user beware:
procedure TAppts.DeleteJunk(Sender: TObject);
const
olMail = $0000002B; olFolderJunk = 23;
var
i, iNbMail: Integer;
Created: Boolean;
EmailSubject, EmailSender: String;
Outlook, Namespace, JunkFolder, Mail: variant;
begin
try
Outlook:=GetActiveOleObject('Outlook.Application') ;
Created := False;
except
Outlook:=CreateOleObject('Outlook.Application') ;
Created := True;
end;try
NameSpace := Outlook.GetNamespace('MAPI');
NameSpace.Logon;JunkFolder:= NameSpace.GetDefaultFolder(olFolderJunk);
iNbMail:= JunkFolder.Items.Count;for i:= iNbMail downto 1 do
begin
Mail := JunkFolder.Items[i];
if Mail.Class <> olMail then Continue;
EmailSender := String(Mail.SenderEmailAddress);
EmailSubject:= String(Mail.Subject);
if (EmailSender = '') or (Pos('Russian Girls', EmailSubject) > 0)
then Mail.Delete;
end;
finally
Outlook := Unassigned;
NameSpace := Unassigned;
JunkFolder := Unassigned;
Mail := Unassigned;
if Created then
begin
Outlook.Quit;
Created := False;
end;
end;
end;