Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-09-24
10
Medium Priority
?
290 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
9 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
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 …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

773 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