The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!
Function findContact(streMail As String) As ContactItem
Dim conFolder As MAPIFolder
Dim strFilter As String
Dim olkContactItems As items
Dim con As ContactItem
Dim intCountItems As Integer
Dim intDelCount As Integer
Set conFolder = Application.Session.GetDefaultFolder(olFolderContacts)
strFilter = "[email1address] = " & Chr(34) & streMail & Chr(34)
Set olkContactItems = conFolder.items.Restrict(strFilter)
If olkContactItems.count <> 0 Then
Set findContact = olkContactItems.GetFirst
Else
strFilter = "[email2address] = " & Chr(34) & streMail & Chr(34)
Set olkContactItems = conFolder.items.Restrict(strFilter)
If olkContactItems.count <> 0 Then
Set findContact = olkContactItems.GetFirst
Else
strFilter = "[email3address] = " & Chr(34) & streMail & Chr(34)
Set olkContactItems = conFolder.items.Restrict(strFilter)
If olkContactItems.count <> 0 Then
Set findContact = olkContactItems.GetFirst
End If
End If
End If
End Function
Sub rule_1(mai As MailItem)
Dim con As Object
If mai.SenderEmailType <> "SMTP" Then Exit Sub
Set con = findContact(mai.sendereMailAddress)
If con Is Nothing Then
Set con = Application.CreateItem(olContactItem)
con.FullName = "Please Name ME"
con.Email1Address = mai.sendereMailAddress
con.Save
End If
End Sub
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Join the community of 500,000 technology professionals and ask your questions.