I need a code to automatically delete my junk email folder

J

Jay Dunaway

Here is what's going on:

I use Spambayes in additional to Rules I created for Outlook 2002.

I would like the following action:
1) all emails arriving into the junk email folder should be forwarded
as an attachement to [email protected] and [email protected]
2) after being forwarded, permanently delete said item from the junk
folder
3) (extra on my wish list), permanently delete the email sent to
[email protected] and [email protected] from the "item sent" forlder

I've been able to use a Rule from the rule wizard to do the first two
steps for the rule called "junk sender" list. I was hoping for some
help on creating a VBA sub to achieve the above.

Thanks. Jay Dunaway
 
E

Eric Legault [MVP - Outlook]

Something like this should do what you want for step 3. Note that to
permanently delete a message, you need to use the Message.Delete method in
CDO. The method below puts it in the Deleted Items folder.

Dim objSentItems As Outlook.MAPIFolder, objSentItem As Object
Dim objItems As Outlook.Items, objNS As Outlook.NameSpace
Dim intX As Integer

Set objNS = Application.GetNamespace("MAPI")
Set objSentItems = objNS.GetDefaultFolder(olFolderSentMail)
Set objItems = objSentItems.Items.Restrict("[To] = '[email protected]'")
For intX = objItems.Count To 1 Step -1
Set objSentItem = objItems.Item(intX)
objSentItem.Delete
Next
 
Top