?
Solved

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

Posted on 2010-01-13
50
Medium Priority
?
284 Views
Last Modified: 2012-05-08
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 ?
0
Comment
Question by:mindwarpltd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 25
  • 22
  • 2
  • +1
50 Comments
 
LVL 76

Expert Comment

by:Alan Hardisty
ID: 26302158
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26302180
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
 
LVL 76

Expert Comment

by:Alan Hardisty
ID: 26302200
That's cheating ;-)
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:mindwarpltd
ID: 26302253
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26302296
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
 

Author Comment

by:mindwarpltd
ID: 26302355
\\Jules\Norton AntiSpam Folder
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26302358
Alternatively a snapshot of the folders in the folder structure will do.

Chris
0
 

Author Comment

by:mindwarpltd
ID: 26302407
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26302588
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
 
LVL 22

Expert Comment

by:senad
ID: 26302593
I would suggest you disable Norton Spam Folder and let
Outlook handle the spam.
0
 

Author Comment

by:mindwarpltd
ID: 26303075
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26303319
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
 

Author Comment

by:mindwarpltd
ID: 26303705
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
 

Author Comment

by:mindwarpltd
ID: 26303773
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26304029
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
 

Author Comment

by:mindwarpltd
ID: 26304214
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26304389
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26304574
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
 

Author Comment

by:mindwarpltd
ID: 26304861
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26306592
There are ways and means ... what version of outlook are you using?

Chris
0
 

Author Comment

by:mindwarpltd
ID: 26306629
xp
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26306650
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
 

Author Comment

by:mindwarpltd
ID: 26306907
OK, I use ClickYes at the moment.

Anyway, the macro isn't deleting.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26307038
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
 

Author Comment

by:mindwarpltd
ID: 26307296
Yes
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26307684
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
 

Author Comment

by:mindwarpltd
ID: 26307862
Its Stops if I add that line and doesn't delete the emails.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26307931
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
 

Author Comment

by:mindwarpltd
ID: 26308154
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26308300
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
 

Author Comment

by:mindwarpltd
ID: 26308558
Hmmm
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26308911
?

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

Chris
0
 

Author Comment

by:mindwarpltd
ID: 26311653
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26311797
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26311856
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
 

Author Comment

by:mindwarpltd
ID: 26311868
Theres nothing in my action list.

I take it, thats bad.

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26311878
Nope ... see my previous 'apology'
0
 

Author Comment

by:mindwarpltd
ID: 26311886
I'm confused...

Are you saying its not possible to do this ?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26311904
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
 

Author Comment

by:mindwarpltd
ID: 26311926
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26311945
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
 

Author Comment

by:mindwarpltd
ID: 26311982
Yes the code works.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26312006
>>> Yes the code works

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

Chris
0
 

Author Comment

by:mindwarpltd
ID: 26312204
Would have liked the enable macros dialog not to appear
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26312320
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
 

Author Comment

by:mindwarpltd
ID: 26312521
Lets just clarify this screen, here...
enablemacros.jpg
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26312549
This is the startup screen and you need to enable macros
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 26312599
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
 

Author Closing Comment

by:mindwarpltd
ID: 31676580
Excellent :)
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26312835
Phew!, of course any other outlook macros in the future should be much easier to support.

Chris
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question