none
IMAP4 and Outlook 2016 duplicate email on mailitem save RRS feed

  • Question

  • Hello,

    We are a small company of 4, two guys working from their home office.

    We all share one IMAP Email-Account hosted on our own in-house server (linux) to be able to work on the same incoming emails.
    In order to stay on top of about 200 incoming emails every day, we use a very simple VBA code to change the subject of emails by the click of an icon (Something like this [*Att Wolfgang*])
    Then we add the extra strings to custom view rules to have different font color, weight, etc. for different strings.
    This worked mostly fine in Outlook 2010. With Outlook 2016 I get duplicates of every mail I am modifying this way.

    I tried changing the VBA Code but no luck there, then I tried to find another mailitem property to place my text in, but the problem is the limitation of the IMAP4 protocol to the most basic fields…
    I am completely stuck here and would very much appreciate any help or tip you could give me concering these questions:

    1. Is there any way to avoid the duplication in the first time
    2. or to check for the duplicate and delete it within the macro
    3. is there any another IMAP4 compatible "field" we could write our string in and read it from there

    Especially the last one I was putting my hope in - whenever I change the "flagged" field with the macro, I dont get a duplicate - but this is only boolean not string. I would need one where string is allowed.

    Here is a code snippet of our VBA Macro:


    Sub IB_Wolfgang() 
    
        Dim myOlExp As Outlook.Explorer
    
        Dim myOlSel As Outlook.Selection
    
        Dim strSubject As String
    
     
    
        Set myOlExp = Application.ActiveExplorer
    
        Set myOlSel = myOlExp.Selection
    
     
    
    If myOlSel.Count = 0 Then
    
            MsgBox "No objects selected."
    
        Else
    
            For Each SelectedItem In myOlSel
    
                If (TypeOf SelectedItem Is Outlook.mailItem) Then
    
                    Dim mailItem As Outlook.mailItem
    
                    Set mailItem = SelectedItem
    
           
    
            strSubject = mailItem.Subject
    
            mailItem.Subject = "[*IB Wolfgang*] " & strSubject
    
            mailItem.Save
    
             End If
    
            Next SelectedItem
    
          End If
    
    End Sub


    Monday, May 15, 2017 1:04 PM

Answers

  • Hi Wolfgang-75,

    you had mentioned that,"Do you have another idea I could try? Maybe the way would be to execute the above code, save the mailitem and then look for duplicate email and delete?"

    you can try to refer code below for deleting the duplicate mails.

    Option Explicit
    
    Sub demo()
        Dim objFolder As Folder
        Dim objDictionary As Object
        Dim i As Long
        Dim objItem As Object
        Dim strKey As String
    
        Set objDictionary = CreateObject("scripting.dictionary")
       
        Set objFolder = Outlook.Application.Session.PickFolder
    
        If Not (objFolder Is Nothing) Then
           For i = objFolder.Items.Count To 1 Step -1
               Set objItem = objFolder.Items.Item(i)
     
               Select Case objFolder.DefaultItemType
                   
                      Case olMailItem
                           strKey = objItem.Subject & "," & objItem.Body & "," & objItem.SentOn
                     
                      Case olAppointmentItem
                           strKey = objItem.Subject & "," & objItem.Start & "," & objItem.Duration & "," & objItem.Location & "," & objItem.Body
                    
                      Case olContactItem
                           strKey = objItem.FullName & "," & objItem.Email1Address & "," & objItem.Email2Address & "," & objItem.Email3Address
                     
                      Case olTaskItem
                           strKey = objItem.Subject & "," & objItem.StartDate & "," & objItem.DueDate & "," & objItem.Body
               End Select
     
               strKey = Replace(strKey, ", ", Chr(32))
     
             
               If objDictionary.Exists(strKey) = True Then
                  objItem.Delete
               Else
                  objDictionary.Add strKey, True
               End If
           Next i
        End If
    End Sub
    
    
    

    Before running the code, you can see duplicate mail in my folder.

    After running the code:

    you can modify code as per your requirement.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Wolfgang-75 Friday, May 19, 2017 12:03 PM
    Friday, May 19, 2017 12:44 AM
    Moderator

All replies

  • Hi Wolfgang-75,

    I try to test the above code on my Outlook 2016.

    the code works correctly, it did not create any duplicate mail and modify the mail subject.

    first I suggest you to repair your Outlook 2016. then try to install the latest updates and then try to test the code again.

    to verify that the issue is related to only your machine, you can try to test the same code on other Outlook 2016 machines.

    let me know about your testing results.

    at present , I think that something get corrupted in your Outlook 2016.

    so try to correct it first.

    if then also issue not solve then we can try to find work around for this issue.

    also check that no any other code get executed when you try to rename the subject.

    if you have any other code then try to test your code separately.

    so that it can help you to narrow down the issue. 

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, May 16, 2017 5:38 AM
    Moderator
  • Hello Deepak,

    thank you for your response and testing the code. As far as I found out it seems to be a common issue, that Outlook 2016 duplicates emails BUT only on IMAP4 Accounts. The code works perfectly on POP Accounts.

    Unfortunately POP does not work for us the way we all work together on the same emails.

    I checked for updates and there are none available. Since this is a fresh install without any other add-ins or anything getting in the way, I did not try to reinstall.

    Do you have another idea I could try? Maybe the way would be to execute the above code, save the mailitem and then look for duplicate email and delete? I only would not feel to comfy with deleting objects without warning but on the other hand, we simply do this a lot and accepting eacht time would be a big time issue :-(

    Thanks :-)

    Wolfgang


    Thursday, May 18, 2017 9:52 AM
  • Hi Wolfgang-75,

    you had mentioned that,"Do you have another idea I could try? Maybe the way would be to execute the above code, save the mailitem and then look for duplicate email and delete?"

    you can try to refer code below for deleting the duplicate mails.

    Option Explicit
    
    Sub demo()
        Dim objFolder As Folder
        Dim objDictionary As Object
        Dim i As Long
        Dim objItem As Object
        Dim strKey As String
    
        Set objDictionary = CreateObject("scripting.dictionary")
       
        Set objFolder = Outlook.Application.Session.PickFolder
    
        If Not (objFolder Is Nothing) Then
           For i = objFolder.Items.Count To 1 Step -1
               Set objItem = objFolder.Items.Item(i)
     
               Select Case objFolder.DefaultItemType
                   
                      Case olMailItem
                           strKey = objItem.Subject & "," & objItem.Body & "," & objItem.SentOn
                     
                      Case olAppointmentItem
                           strKey = objItem.Subject & "," & objItem.Start & "," & objItem.Duration & "," & objItem.Location & "," & objItem.Body
                    
                      Case olContactItem
                           strKey = objItem.FullName & "," & objItem.Email1Address & "," & objItem.Email2Address & "," & objItem.Email3Address
                     
                      Case olTaskItem
                           strKey = objItem.Subject & "," & objItem.StartDate & "," & objItem.DueDate & "," & objItem.Body
               End Select
     
               strKey = Replace(strKey, ", ", Chr(32))
     
             
               If objDictionary.Exists(strKey) = True Then
                  objItem.Delete
               Else
                  objDictionary.Add strKey, True
               End If
           Next i
        End If
    End Sub
    
    
    

    Before running the code, you can see duplicate mail in my folder.

    After running the code:

    you can modify code as per your requirement.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Wolfgang-75 Friday, May 19, 2017 12:03 PM
    Friday, May 19, 2017 12:44 AM
    Moderator
  • Hi Deepak,

    Thanks again for your help. I tried this code and it works with some addition. In each of my makros changing subject and saving the mailitem, I call the "delete duplicate" at the end. Unfortunately, the duplicates only show up, once the folder is refreshed so I had to add another macro to switch folders to sentitems and back to inbox to refresh and then delete the duplicates.

    This works but is not really an ellegant solution.

    I can work with this now but my next aim is towards adding my extra information through the IMAP protocol to an email. I only need to find a value that alows strings and is fully compatible with IMAP4. Once I figured out which record I can "abuse" for my own string, the rest is simple. Any Ideas on that?

    Thanks and best reagards

    Wolfgang

    Friday, May 19, 2017 12:03 PM