Solved

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

Posted on 2010-11-30
16
534 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
[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
  • 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 (Outlook MVP)
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 (Outlook MVP)
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 (Outlook MVP)
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

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.

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…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 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