You are an 'End If' and a '.Save' missing but apart from that it seems to work e.g. If I change to my domain then
Sub Filer(item As Outlook.MailItem)
Dim olkUDP2 As Outlook.UserProperty
Dim recip As Outlook.Recipient
Dim udp2value As String
Dim i As Long
If item.Class = olMail Then
For i = 1 To item.Recipients.Count
Set recip = item.Recipients.item(i)
If InStr(recip.Address, "gmayor.com") > 0 Then
Set olkUDP2 = item.UserProperties.Add("Filer", olText, True)
olkUDP2.Value = recip.Address
Exit For
End If
Next i
item.Save
End If
End Sub
will work for my domain. Use the following macro to read the value
Sub GetFiler(item As Outlook.MailItem)
Dim olkUDP2 As Outlook.UserProperty
Set olkUDP2 = item.UserProperties("Filer")
MsgBox olkUDP2.Value
End Sub
You can use the following to apply or test the property
Sub GetMsg()
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.item(1)
GetFiler olMsg 'Read the value
'Filer olMsg 'Write the value
lbl_Exit:
Exit Sub
End Sub