Solved

a script to move oldest email messages from the inbox to another folder

Posted on 2010-11-30
16
528 Views
Last Modified: 2012-06-27
I am looking for a script that search for the oldest email messages (by date) and move what found to another folder, lets call it back up. also a check should occure to find out if the backup folder exist if not create one.
0
Comment
Question by:JAWC
  • 6
  • 6
  • 3
  • +1
16 Comments
 
LVL 8

Expert Comment

by:sjl1986
ID: 34239330
I use the software from Pergenex called Auto-Mate.

It lets you choose exactly what criteria to search for and you can specify how long you want the email to sit in your inbox before it moves it out. I set things like newsletters to automatically delete after 2 days, etc. It only works with Outlook unfortunately, so to use it on my Gmail account, I have my Gmail setup as IMAP in Outlook. Hope this helps.

http://www.pergenex.com/index.shtml
0
 

Author Comment

by:JAWC
ID: 34239373
thank you for the suggestion. unfortunately we are not able to purchase software
0
 
LVL 14

Expert Comment

by:Alexei Kuznetsov
ID: 34240843
No need to purchase. This free tool can do that easily, just configure required data range:
http://www.outlookfreeware.com/en/products/all/OutlookFolderMerge/
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:JAWC
ID: 34247013
Thankyou thims. it did not work I am afraid
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34247042
a script to take all the 'old' mails and move them.

1. How will date and folders be defined?
2. How is the script to be triggered?

Chris
0
 
LVL 14

Expert Comment

by:Alexei Kuznetsov
ID: 34247969
JAWC, what exactly did not work?
0
 

Author Comment

by:JAWC
ID: 34247991
Hi thims
it did not do what we wanted to do.it does come out with errors.
0
 
LVL 14

Expert Comment

by:Alexei Kuznetsov
ID: 34251356
JAWC you can always contact OutlookFreeware.com team on their forum. They will be happy to help you.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34252665
As are we! ... if you want a script then please advise so it can be set up accordingly and otherwise i'll assume you dont.

Chris
0
 

Author Comment

by:JAWC
ID: 34256097
Hi Chris, a script to take all the 'old' mails and move them. Yes

1. How will date and folders be defined? anything older then 5 month
2. How is the script to be triggered? a vbscript or by macro.

Thank you for your help
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34256474
The trigger ... a VBS cannot do so as outlook doesn't support that but the question was within outlook VBE are you comfortable with running a macro we provide?

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34256561
Which folder(s) since that affects the mechanism

Chris
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 34256714
The following will go through every folder in teh PST and move the 'old' mails to a folder off the PST root named "ReallyOlduns" ... see the code and replace the folder name as appropriate.

call sub moveold to start the process.

Chris
Sub moveOld()
Dim srcFolder As Object
Dim destfolder As Object
Dim subFolder As Object

   Set srcFolder =
Application.Session.GetDefaultFolder(olFolderSentMail).Parent
   Set destfolder = olNav2Folder(srcFolder.folderPath & "\" &
"ReallyOlduns", True)
   For Each subFolder In srcFolder.Folders
       processSubFolders subFolder, destfolder
   Next
'    strFilter = "[SentOn] >= '" & Format(Date + TimeSerial(0, 0, 0),
"ddddd h:nn AMPM") & "'" & " and " & "[senton] <= '" & Format(Date +
TimeSerial(23, 59, 59), "ddddd h:nn AMPM") & "'"
'    Set olmailitems = myfolder.items.Restrict(strFilter)
'    For Each mai In olmailitems

End Sub

Sub processSubFolders(fldr As Object, destfolder As Object)
Dim subFolder As Object
Dim strFilter As String
Dim olMailItems As Variant
Dim mai As mailitem

   For Each subFolder In fldr.Folders
       processSubFolders subFolder, destfolder
   Next
   strFilter = "[SentOn] <= '" & Format(DateAdd("m", -5, Date) +
TimeSerial(23, 59, 59), "ddddd h:nn AMPM") & "'"
   If fldr.items.Count > 0 Then
       Set olMailItems = fldr.items.Restrict(strFilter)
       For Each mai In olMailItems
           mai.Move destfolder
       Next
   End If

End Sub

Public Function olNav2Folder(foldername As String, Optional
createFolders As Boolean) As Object
Dim olApp As Object
Dim olNs As Object
Dim olfldr As Object
Dim reqdFolder As Object
Dim arrFolders() As String
Dim nestCount As Integer

   On Error Resume Next
   foldername = Replace(Replace(foldername, "/", "\"), "\\", "")
   If Right(foldername, 1) = "\" Then foldername = Left(foldername,
Len(foldername) - 1)
   arrFolders() = Split(foldername, "\")
   Set olApp = CreateObject("Outlook.Application")
   Set olNs = olApp.GetNamespace("MAPI")
   Set reqdFolder = olNs.Folders.item(arrFolders(0))
   For nestCount = 1 To UBound(arrFolders)
       If Not reqdFolder Is Nothing Then
           Set olfldr = reqdFolder.Folders
           Set reqdFolder = olfldr.item(arrFolders(nestCount))
           If reqdFolder <> olfldr.item(arrFolders(nestCount)) Then
               If createFolders Then
                   reqdFolder.Folders.Add (arrFolders(nestCount))
                   Set olfldr = reqdFolder.Folders
                   Set reqdFolder = olfldr.item(arrFolders(nestCount))
               Else
                   Set reqdFolder = Nothing
                   Exit For
               End If
           End If
       Else
       End If
   Next
   Set olNav2Folder = reqdFolder
   Set olApp = Nothing
   Set olNs = Nothing
   Set olfldr = Nothing
   Set reqdFolder = Nothing
End Function

Open in new window

0
 

Author Comment

by:JAWC
ID: 34256731
I just looked at the security settings macro will not work.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34256765
ENable the macros then, or are you saying that your IT have disbled you from running scripts ... because if so a script as requested can never work!

Chris
0
 

Author Closing Comment

by:JAWC
ID: 34256897
Thank you this is excellent. We have a good start.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

776 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