Solved

Need a script to organize my mails in Outlook

Posted on 2014-11-06
2
217 Views
Last Modified: 2014-11-20
Hi Experts i found a script on http://www.slipstick.com/developer/delete-older-messages-new-message-arrives/

Sub DeleteOlderMessages(Item As Outlook.MailItem)
 
Dim objInbox As Outlook.MAPIFolder
Dim intCount As Integer
Dim objVariant As Variant
 
Set objInbox = Session.GetDefaultFolder(olFolderInbox)
 
' Remove these lines if you don't want to add a category
Item.Categories = "Delete Older"
Item.Save
 
For intCount = objInbox.Items.Count To 1 Step -1
 Set objVariant = objInbox.Items.Item(intCount)
 If objVariant.MessageClass = "IPM.Note" Then
    If objVariant.Subject = Item.Subject And objVariant.SentOn < Item.SentOn Then
     objVariant.Delete
     Else
    End If
 End If
Next
 
Set objInbox = Nothing
End Sub

This will delete Mails with the same subject. I am in the need for the similar situation but my subjects are in one word different.

Explaination: I am getting from nagios status mails. I can not access directly to the system so i need to keep track of the status. So my idea is to have a rule set like this:
1.) when mail arrive i move them to a folder named like the system
2.) if in the subject is ** PROBLEM then it should keep it
3.) if in the subject is ** RESOLVED it should remove both the ** Problem one and the ** RESOLVED one

Can someone help me out?
If necessary i can install a tool instead of the rules in Outlook. But i did not find any tool what is doing that.
I have no access to exchange itself so i need a client solution.
0
Comment
Question by:Wilder_Admin
2 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 40427548
So there will never be more than two messages in a given system's folder?
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 40454001
The guts of what you need are here
Public WithEvents myOlItems As Outlook.Items
Public Sub Application_Startup()
   ' Reference the items in the Inbox. Because myOlItems is declared
   ' "WithEvents" the ItemAdd event will fire below.
   Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)
      ' Check to make sure it is an Outlook mail message, otherwise
      ' subsequent code will probably fail depending on what type
      ' of item it is.
      If TypeName(Item) = "MailItem" Then
            Select Case True
                 Case Item.Subject Like "** PROBLEM"
                      'code to move the item to a particular folder
                 Case Item.Subject Like "** RESOLVED"
                      'code to search a particular folder for an item with subject like "** PROBLEM"
                      'if found, that item is deleted and the resolved email is also deleted.
                 Case Else
                       'any code you may want to fire in the event of mailings without the critical words
        End Select
      End If
End Sub

Open in new window


If you need more help, more detail about the subjects of the items, and the folders will be required.
I can't code for what I have no information about.
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

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
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…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

685 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