Solved

How to Update a Outlook contact user field identifying those that had a read receipt

Posted on 2014-09-24
10
276 Views
Last Modified: 2014-10-01
I am trying to Update a Outlook contact user field identifying those that had a read receipt

The code fails at varAdr = olkMsg.SenderEmailAddress, I think its because a return receipt is different from a regular email - but I'm stumped with how cto adapt and =internet searches were fruitless

Sub UpdateContactBasedOnFromEmailAddressEmail()
    Dim oOlApp As Outlook.Application
    Dim objNmSpc As NameSpace
    Dim ofldr As Object
    Dim ContFldr As Object
    Dim UpdateUserFieldYN As Integer
    Dim UpdtCount1 As Integer
    Dim olkMsg As Object, olkCon As Outlook.ContactItem, arrAdr As Variant, varAdr As Variant
   
    Set oOlApp = Outlook.Application
    Set objNmSpc = oOlApp.GetNamespace("MAPI")
   
    MsgBox "Select Email Folder"
    Set ofldr = objNmSpc.PickFolder
   
    MsgBox "Select Contacts Folder"
    Set ContFldr = objNmSpc.PickFolder

    MsgBox "Email Folder - " & ofldr & vbNewLine & "Contacts - " & ContFldr
   
    UpdateUserFieldYN = MsgBox("This Process Upadates User3 Field - Do You Want to Proceed?", vbYesNo)
   
    If UpdateUserFieldYN = 6 Then
        UpdtCount1 = 1
        For Each olkMsg In ofldr.Items
            If olkMsg.Class = olMail Or olkMsg.Class = 46 Then
                varAdr = olkMsg.SenderEmailAddress
'MsgBox varAdr & vbNewLine & olkMsg.Subject
                    Set olkCon = ContFldr.Items.Find("[Email1Address] = '" & varAdr & "'")
                    If TypeName(olkCon) = "ContactItem" Then
                        olkCon.User3 = "zzz - " & olkMsg.Subject
                        olkCon.Save
                    End If
           
                    UserForm1.TextBox1 = "Email " & varAdr & " " & olkMsg.Subject
                    UserForm1.TextBox2 = UpdtCount1
                    UserForm1.Show vbModeless
                    DoEvents
                               
                    UpdtCount1 = UpdtCount1 + 1
            End If
        Next
    End If
   
    Set olkCon = Nothing
    Set ContFldr = Nothing
    Set olkMsg = Nothing
       
    Unload UserForm1
       
    MsgBox "Macro Complete"
End Sub
0
Comment
Question by:rogerdjr
  • 6
  • 3
10 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 40343603
Hello again, rogerdjr.

Read receipts are of a class called ReportItem.  While they do not have a SenderEmailAddress property, they do in fact contain the address of the sender.  You just have to use the PropertyAccessor object to get that address.  I've added that functionality in the GetSenderSMTP function.  The only other change required was to implement a conditional statement to get the address from the SenderEmailAddress property if the item is an email or from the GetSenderSMTP function if the item is a receipt.  

I also removed the code that created an instance of Outlook's Application and NameSpace objects.  It's not necessary to create those in an Outlook macro.  The Application object and Session object are both already available, so creating another instance of them is unnecessary.

Sub UpdateContactBasedOnFromEmailAddressEmail()
    Dim ofldr As Object
    Dim ContFldr As Object
    Dim UpdateUserFieldYN As Integer
    Dim UpdtCount1 As Integer
    Dim olkMsg As Object, olkCon As Outlook.ContactItem, arrAdr As Variant, varAdr As Variant
      
    MsgBox "Select Email Folder"
    Set ofldr = Session.PickFolder
   
    MsgBox "Select Contacts Folder"
    Set ContFldr = Session.PickFolder

    MsgBox "Email Folder - " & ofldr & vbNewLine & "Contacts - " & ContFldr
   
    UpdateUserFieldYN = MsgBox("This Process Upadates User3 Field - Do You Want to Proceed?", vbYesNo)
   
    If UpdateUserFieldYN = 6 Then
        UpdtCount1 = 1
        For Each olkMsg In ofldr.Items
            If olkMsg.Class = olMail Or olkMsg.Class = olReport Then
                Select Case olkMsg.Class
                    Case olMail
                        varAdr = olkMsg.SenderEmailAddress
                    Case olReport
                        varAdr = GetSenderSMTP(olkMsg)
                End Select
'MsgBox varAdr & vbNewLine & olkMsg.Subject
                    Set olkCon = ContFldr.Items.Find("[Email1Address] = '" & varAdr & "'")
                    If TypeName(olkCon) = "ContactItem" Then
                        olkCon.User3 = "zzz - " & olkMsg.Subject
                        olkCon.Save
                    End If
           
                    UserForm1.TextBox1 = "Email " & varAdr & " " & olkMsg.Subject
                    UserForm1.TextBox2 = UpdtCount1
                    UserForm1.Show vbModeless
                    DoEvents
                               
                    UpdtCount1 = UpdtCount1 + 1
            End If
        Next
    End If
   
    Set olkCon = Nothing
    Set ContFldr = Nothing
    Set olkMsg = Nothing
       
    Unload UserForm1
       
    MsgBox "Macro Complete"
End Sub

Function GetSenderSMTP(olkMsg)
    Dim olkPA
    On Error Resume Next
    Set olkPA = olkMsg.PropertyAccessor
    MeetingSenderSMTP = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C1F001E")
    On Error GoTo 0
    Set olkPA = Nothing
End Function

Open in new window

0
 

Author Comment

by:rogerdjr
ID: 40344049
Thanks a million - I'm out of the office till Sat. - will test this on Sat.
0
 

Author Comment

by:rogerdjr
ID: 40348023
Works great for the  emails that have the message class 43 - IPM.Note but skips over the messages with a message class 46 - Report.ipm.note.IPNRN or Report.ipm.note.IPNnRN
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:rogerdjr
ID: 40348024
Is there a place I can learn about the message classes and how they function?
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 40349770
I don't know how it can skip over the items with a class of 46.  You can see that the code looks for those items too.  I jsut ran the code here and it processed my class 46 items.  I did notice one problem though.  I've a typo in the GetSenderSMTP function.  Please replace that function with the version below.

You can read about each message class in the online documentation.  The documentation describes the properties, methods, and events of each class.

Function GetSenderSMTP(olkmsg)
    Dim olkPA
    On Error Resume Next
    Set olkPA = olkmsg.PropertyAccessor
    GetSenderSMTP = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C1F001E")
    On Error GoTo 0
    Set olkPA = Nothing
End Function

Open in new window

0
 

Author Comment

by:rogerdjr
ID: 40350356
Function and macro work perfectly now thanks a million

I tried to find something on line searching outlook 2013 message class - found this link but http://msdn.microsoft.com/en-us/library/office/ff861573(v=office.15).aspx could not find anything that tells me what a message class 43 or 46 mean - could you help with a location for a cross reference or a process in a message box that shows the actual message class like "IPM.Note"

I also found this website that shows how to expose message properties

Thanks again
0
 

Author Comment

by:rogerdjr
ID: 40350472
I've requested that this question be closed as follows:

Accepted answer: 0 points for rogerdjr's comment #a40350356

for the following reason:

Great assistance - thanks alot
0
 
LVL 76

Expert Comment

by:David Lee
ID: 40350473
Sorry, but I have to object to closing the question without getting any credit when I clearly helped.
0
 

Author Comment

by:rogerdjr
ID: 40350519
Sorry - my oversight I thought I accepted BlueDevilFan's solution and gave full credit to BlueDevilFan

HE WAS OF GREAT ASSISTANCE AND SHOULD GET FULL Credit
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
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…
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…

808 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