I need a code to automatically delete my junk email folder

  • Thread starter Thread starter Jay Dunaway
  • Start date Start date
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 (e-mail address removed) and (e-mail address removed)
2) after being forwarded, permanently delete said item from the junk
folder
3) (extra on my wish list), permanently delete the email sent to
(e-mail address removed) and (e-mail address removed) 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
 
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] = '(e-mail address removed)'")
For intX = objItems.Count To 1 Step -1
Set objSentItem = objItems.Item(intX)
objSentItem.Delete
Next
 
Back
Top