Solved

Need a script to organize my mails in Outlook

Posted on 2014-11-06
2
204 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Use email signature images to promote corporate certifications and industry awards.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now