Solved

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

Posted on 2014-09-24
10
266 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
 

Author Comment

by:rogerdjr
ID: 40348024
Is there a place I can learn about the message classes and how they function?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Outlook Free & Paid Tools
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
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: …

743 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

11 Experts available now in Live!

Get 1:1 Help Now