Add email collection

Hello,
I add all emails from contact to message by:

For Each VCardEmail In VCardContact.Emails
MapiMessage.Recipients.Add(VCardEmail.EmailAddress, VCardEmail.EmailAddress, MapiRecipientType.MAPI_TO)
Next

Kindly advise how to prevent adding duplicate emails to the MapiMessage.Recipients collection?
This is my function:

For Each MyEmail As MapiRecipient In MapiRecipientCollection

Dim MyRecipient As String = String.Empty
If String.IsNullOrWhiteSpace(MyEmail.EmailAddress) = False Then
   MyRecipient = MyEmail.EmailAddress
ElseIf String.IsNullOrWhiteSpace(MyEmail.OrganizationEmailAddress) = False Then
   MyRecipient = MyEmail.OrganizationEmailAddress
End If

If MyRecipient = InputEmail Then Return True

First I didn’t know MapiRecipient can contain how many email address fields, so found and compared against EmailAddress and OrganizationEmailAddress

Second was not sure if there’s a method/property to check existence or duplicate preventing?

There is no such public method/property to check existence or duplicate preventing.

1 Like

Thanks for confirming, can you please verify if this way is correct?

If String.IsNullOrWhiteSpace(MyEmail.EmailAddress) = False Then
   MyRecipient = MyEmail.EmailAddress
ElseIf String.IsNullOrWhiteSpace(MyEmail.OrganizationEmailAddress) = False Then
   MyRecipient = MyEmail.OrganizationEmailAddress
End If

No idea if EmailAddress vs OrganizationEmailAddress can be different or both empty etc

I think that’s the correct way.