Is it possible and if so how, to have a rule which deletes what in my spam folder in outlook after 1 day?

I have a spam folder which my anti virus / spam program uses to put in spam emails.

I'm just wondering if its possible to have a rule in outlook which will empty that folder after a day ?

If so, how ?
mindwarpltdAsked:
Who is Participating?
 
Chris BottomleyConnect With a Mentor Commented:
Now goto alt +F11 for the VBE

Ensure you have created a certificate via self cert
Now once you start outlook and get the disable/enable/info screen select enable then:
Tools | Digital Signature | choose | the one you created with self cert
Ok back to the VBE screen
Save the VBE and then close VBE
Close outlook - save project yes

Restart Outlook:
Enable macros
Then in the security warning box:
Check always trust macros from this publisher, (MAcros by your certificate name)
click enable macros

ALl should be well once all is saved and on restart no prompt

Chris
0
 
Alan HardistyCo-OwnerCommented:
I am not aware that you can do this with a rule.  There are no options to do this even in Outlook 2010.  You may be able to setup AutoArchive to permanently delete mail after a day and only setup that folder, but that's about it that I can think of.
0
 
Chris BottomleyCommented:
Hello mindwarpltd,

If macros are acceptable then you can have a macro that deletes anything in that folder older than 1 day when the application opens or closes .. and if so we can help there.

Regards,

chris_bottomley
0
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
Alan HardistyCo-OwnerCommented:
That's cheating ;-)
0
 
mindwarpltdAuthor Commented:
Can you provide the macro?

I'm not really sure what to do with, so I'll need full instructions.

I'm using outlook xp
0
 
Chris BottomleyCommented:
First off lets see if we establish teh correct folder.

IN outlook place the cursor on teh junk mail folder in question
In outlook press alt + f11 to open the editor, (VBE)
In the VBE press ctrl + G to open the immediate window ... it has the heading Immediate when opened!
In teh Immediate window type:
    ?application.activeexplorer.currentfolder.folderpath

Let me know what it returns.

Chris
0
 
mindwarpltdAuthor Commented:
\\Jules\Norton AntiSpam Folder
0
 
Chris BottomleyCommented:
Alternatively a snapshot of the folders in the folder structure will do.

Chris
0
 
mindwarpltdAuthor Commented:
0
 
Chris BottomleyCommented:
In the VBE:

Insert | Module ... YOu will now have a module under the project root in the project window, (ctrl + R).

In this module insert the following snippet, there is one more step which i'll cover in a few minutes

Chris
Sub filterJunk()
Dim fldr As Object
Dim intItem As Integer
Dim strFilter As String
Dim olmailitems As Outlook.items
    
    On Error Resume Next
    Set fldr = Application.Session.folders("Jules").folders("Norton AntiSpam Folder")
    strFilter = "[ReceivedTime] <= '" & Format(DateAdd("d", -1, Date) + TimeSerial(0, 0, 0), "mm/dd/yyyy h:nn AMPM") & "'"
    Set olmailitems = fldr.items.Restrict(strFilter)
    
    ' process all the items in this folder
    For intItem = olmailitems.count To 1 Step -1
        objItem.Delete
    Next
'    Debug.Print fldr.items.count & vbTab & olmailitems.count

End Sub

Open in new window

0
 
senadCommented:
I would suggest you disable Norton Spam Folder and let
Outlook handle the spam.
0
 
mindwarpltdAuthor Commented:
OK Chris Done.

Senad, I'm not using norton anymore, but kept the folder Iuse kaspersky and my isp has spam prefixes on the subject lines.
0
 
Chris BottomleyCommented:
Apologies i've discovered a bug during the last rewrite, Use the snippet below in teh module instead.

When that is done in the vBE thisoutlooksession~

LH dropdown select APplication
RH dropdown select startup

Simply type the one line between the sub bounds that should have been 'created as:
Private Sub Application_Startup()
End Sub

so that it becomes

Private Sub Application_Startup()
    filterJunk
End Sub

Close the VBE and check outlook to see if there are mails to be deleted in the folder.

Now close outlook >>> SAVE THE CODE <<< and after a moment or 2 re-open.  It should delete the files from midnight the day before last, i.e if today is Wed then anything before midnight Mon/Tues.

Chris
Sub filterJunk()
Dim fldr As Object
Dim intItem As Integer
Dim strFilter As String
Dim olmailitems As Outlook.items
    
    On Error Resume Next
    Set fldr = Application.Session.folders("Jules").folders("Norton AntiSpam Folder")
    strFilter = "[ReceivedTime] <= '" & Format(DateAdd("d", -1, Date) + TimeSerial(0, 0, 0), "mm/dd/yyyy h:nn AMPM") & "'"
    Set olmailitems = fldr.items.Restrict(strFilter)
    
    ' process all the items in this folder
    If olmailitems.count = 0 Then Exit Sub
    For intItem = olmailitems.count To 1 Step -1
        olmailitems(intItem).Delete
    Next
'    Debug.Print fldr.items.count & vbTab & olmailitems.count

End Sub

Open in new window

0
 
mindwarpltdAuthor Commented:
Hmmm I don't think its doing anything.

I dragged lots of emails from the last few days into my spam folder and restarted outlook at the count of emails is the same..
0
 
mindwarpltdAuthor Commented:
I think macros must be turned off or not running as I put...

msbox "hello" in application_startup and its didn't show a message box.
0
 
Chris BottomleyCommented:
Check Security as appropriate:
------------------------------

In the application select Tools | Macro | Security
2003 and Earlier : Select Medium
2007 : Warnings for all Macros
Select OK

Chris
0
 
mindwarpltdAuthor Commented:
Ahh it was set to high...

It also deleted everything in the folder :(

I'm in the UK, with the date format make a difference in your code?
0
 
Chris BottomleyCommented:
First up my apologies I re-used some code so didn't test in depth but whilst I cannot yet see why I have the same experience when I test so I am looking into it.

Chris
0
 
Chris BottomleyCommented:
Not surprisingly most of solutions goto the US but i'm also UK.  I have tested a mod as follows which works fine for me in the UK

Chris
Sub filterJunk()
Dim fldr As Object
Dim intItem As Integer
Dim strFilter As String
Dim olmailitems As Outlook.items
    
    On Error Resume Next
'    Set fldr = Application.Session.folders("Jules").folders("Norton AntiSpam Folder")
    Set fldr = Application.Session.GetDefaultFolder(olFolderInbox).folders("CBOTTOM1")
    strFilter = "[ReceivedTime] <= '" & Format(DateAdd("d", -1, Date) + TimeSerial(0, 0, 0), "mmm/dd/yyyy h:nn AMPM#") & "'"
    Set olmailitems = fldr.items.Restrict(strFilter)
    
    ' process all the items in this folder
    If olmailitems.count = 0 Then Exit Sub
    For intItem = olmailitems.count To 1 Step -1
        olmailitems(intItem).Delete
    Next
'    Debug.Print fldr.items.count & vbTab & olmailitems.count

End Sub

Open in new window

0
 
mindwarpltdAuthor Commented:
I set security to medium earlier and I get a message each time do I want to enable macros etc.

I don't know if this is stopping the startup macro running.
But nothing deleted at the moment.

Ahh no setting it to low doesn't make a difference.

I take it, I'd have to set the security to low to stop the message appearing.
Is it dangerous to do that?

Kind of putting me off the macro route a bit.
0
 
Chris BottomleyCommented:
There are ways and means ... what version of outlook are you using?

Chris
0
 
mindwarpltdAuthor Commented:
xp
0
 
Chris BottomleyCommented:
Try:

MapiLab Outlook security, (http://www.mapilab.com/outlook/security) ... The one I use routinely
Alternatively  clickyes, (http://www.contextmagic.com/)

To use mapilab, download, install then the first time you do something click do this every time and accept it then the next time the warning is no more.  SO set the macro warning back to medium and run the script ... you'll get a warning, as long as you agree and always take this action is selected then that will be the last time ... HE said!

Chris
0
 
mindwarpltdAuthor Commented:
OK, I use ClickYes at the moment.

Anyway, the macro isn't deleting.
0
 
Chris BottomleyCommented:
Since it should be deleting on startup, have you restored mails to that folder i.e. are any of them older than midnight Mon/Tues?

Chris
0
 
mindwarpltdAuthor Commented:
Yes
0
 
Chris BottomleyCommented:
OK is it being called at all? ... in the VBE goto the sub and modify the line:

    On Error Resume Next
to 2 lines as
    Stop
    On Error Resume Next

The macro if it runs should now stop on that line ... press F5 and it should run to completion ... if it stops I will mofify the routine to provide some data for fault finding.

Chris
0
 
mindwarpltdAuthor Commented:
Its Stops if I add that line and doesn't delete the emails.
0
 
Chris BottomleyCommented:
It is possible I need to sneak into the corner and by sleight of hand change the code over while you aren't looking.

Or to explain it is possible you didn't see how I tested it because I changed a line for that purpose ... and corrected it below.  Please replace the sub with this correction.

Chris
Sub filterJunk() 
Dim fldr As Object 
Dim intItem As Integer 
Dim strFilter As String 
Dim olmailitems As Outlook.items 
     
    On Error Resume Next 
    Set fldr = Application.Session.folders("Jules").folders("Norton AntiSpam Folder") 
    strFilter = "[ReceivedTime] <= '" & Format(DateAdd("d", -1, Date) + TimeSerial(0, 0, 0), "mmm/dd/yyyy h:nn AMPM#") & "'" 
    Set olmailitems = fldr.items.Restrict(strFilter) 
     
    ' process all the items in this folder 
    If olmailitems.count = 0 Then Exit Sub 
    For intItem = olmailitems.count To 1 Step -1 
        olmailitems(intItem).Delete 
    Next 
'    Debug.Print fldr.items.count & vbTab & olmailitems.count 
 
End Sub

Open in new window

0
 
mindwarpltdAuthor Commented:
Ahhh cool that worked.

I've installed MapiLab but it didn't give me the option to do this everytime as you mentioned.

Its not a yes no box.

Its enable macros, disable macros and I think help or cancel.
0
 
Chris BottomleyCommented:
I'm using 2007 so my days with such are much reduced and besides every use is already captured by MAPILAB on my work PC so I simply don't see it.

Just checked the web page and it's allow access after first selecting the always do this action, (at the bottom of the advanced security pop up).

Chris
0
 
mindwarpltdAuthor Commented:
Hmmm
0
 
Chris BottomleyCommented:
?

Are you getting the mapilab prompts as sampled on their web site?

Chris
0
 
mindwarpltdAuthor Commented:
Its appears on the oulook menus but its invisible when starting outlook.

I've just uninstalled and re-installed and nothing changed.

The only thing which concerns me, is that when I first installed yesterday there was a big messagebox with do you want o see this again, I checked it to say no I didn't.

:(
0
 
Chris BottomleyCommented:
If you did the always accept then all should be well ... it is 'sticky' and you can for example check teh action list to see that everything is selected as allow, (assuming you haven't deliberately disallowede anything since installing.  See the mapilab actionlist from teh start menu and make sure all entries are allowed, (assuming as I said you have not yet specifically used mapilab to disallow anything so far).

Chris
0
 
Chris BottomleyCommented:
I have been reviewing somewhat and in teh case of MAPILAB it is about allowing other applications to use outlook!

When running outlook you should simply be ok so the question is does the code as supplied strip out the old mails from teh junk folder.

CHris
0
 
mindwarpltdAuthor Commented:
Theres nothing in my action list.

I take it, thats bad.

0
 
Chris BottomleyCommented:
Nope ... see my previous 'apology'
0
 
mindwarpltdAuthor Commented:
I'm confused...

Are you saying its not possible to do this ?
0
 
Chris BottomleyCommented:
I humbly apologise for confusing matters:

1. No I am NOT saying it's impossible quite the opposite.
2. Outlook should simply work in itself happily doing what you want, therefore the question is ... is it working today and if not can we work back from what is happening because it ought to be working as is with the code I posted in http:Q_25050821.html#a26307931

Chris
0
 
mindwarpltdAuthor Commented:
OK.

Thanks for your continued interest with such little reward.

Since uninstalling and re-installing didn't work, I'm not sure what to do next.
0
 
Chris BottomleyCommented:
1. Ignore MAPILAB it was a red herring, does no harm to leave it installed as it is a good program if you want to use outlook features in other applications at some later date.

2. Look to the code itself, does it work, does it get called ... repeat the add stop command from earlier to ensure it is being called.  Let me know.

>>> Thanks for your continued interest with such little reward.
I made it difficult due to my recent lack of familiarity with outlook 2003 security therefore thank you for giving me the time to overcome that failing!

Chris
0
 
mindwarpltdAuthor Commented:
Yes the code works.
0
 
Chris BottomleyCommented:
>>> Yes the code works

As in all is well or is there some issue that needs to be worked through?

Chris
0
 
mindwarpltdAuthor Commented:
Would have liked the enable macros dialog not to appear
0
 
Chris BottomleyCommented:
Are you referring to the dialog on outlook start up if so try a self cert of the vba, (and I unset everything in my outlook to test this properly!):

Note: Signatures created with SelfCert program are personal not commercial.  i.e. The certificate does not verify your identity, for commercial certificates see in the first place: http://officeupdate.microsoft.com/office/redirect/fromOffice9/cert.htm       
      
To create a 2000-2003 selfcert certificate &      
      
      1. Start menu | Programs | Windows Explorer
      2. Navigate to the "Program Files\Microsoft Office\Office" folder
      3. ExecuteSelfCert.exe
      NOTE: If not found then rerun Setup for Office CD1 and click Add or Remove Features. Click the plus sign (+) next to Office Tools; click Digital Signature for VBA Projects and then click Run from My Computer. Click Update Now.

In outlook VBA:
Tools | digital signature | choose ... the name you created above and select saving VBA project.
close then reopen outlook and always trust macros from your certificate.
close and reopen ought not get the prompt

Chris
0
 
mindwarpltdAuthor Commented:
Lets just clarify this screen, here...
enablemacros.jpg
0
 
Chris BottomleyCommented:
This is the startup screen and you need to enable macros
0
 
mindwarpltdAuthor Commented:
Excellent :)
0
 
Chris BottomleyCommented:
Phew!, of course any other outlook macros in the future should be much easier to support.

Chris
0
All Courses

From novice to tech pro — start learning today.