Solved

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

Posted on 2014-09-24
10
277 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Google calendar in MS outlook 3 48
Outlook - Windows to Mac 7 36
Office 365 Resource Calendars aka "Rooms" 4 35
Outlook contact memory 2 17
Read this checklist to learn more about the 15 things you should never include in an email signature.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
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 Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

713 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