0

I am having trouble detecting an in-firm (EX type) invalid email address of an outlook recipient using the following code:

The invalid email address has a typographical error say, tes@mail.com for test@mail.com.

How do I detect an in-firm recipient having an invalid email address?

Dim Email as Outlook.Mailitem
Dim Recipients As Outlook.Recipients
Set Recipients = Email.Recipients
    Recipients.Resolveall

If Not Recipients.ResolveAll Then
    For i = Recipients.Count To 1 Step -1
        If Not Recipients(i).Resolved Then
            MsgBox Recipients(i).Name
        End If
    Next i
End if
Barok
  • 151
  • 1
  • 15

1 Answers1

0

Have you checked the following code:

    Public Function ResolveDisplayNameToSMTP(sFromName, OLApp As Object) As String

    Dim oRecip As Object  'Outlook.Recipient

    Set oRecip = OLApp.Session.CreateRecipient(sFromName)
    oRecip.Resolve
    oRecipName = oRecip.Name

    If oRecip.Resolved And InStr(oRecipName, "@") = 0 Then
        ResolveDisplayNameToSMTP = "Valid"
    Else
        ResolveDisplayNameToSMTP = "Not Valid"
    End If

End Function

For more, please see this: VBA CODE to Verify Email Address Found in Outlook Global Address List

Simon Li
  • 303
  • 2
  • 4
  • 1
    Checking for "@" is not a good idea - oRecip.AddressEntry.Type == "EX" is a better check. – Dmitry Streblechenko Dec 13 '18 at 22:28
  • It seems that if a syntax error is found in the email address of an in-firm recipient say while typing it into the mailitem, outlook does not see the recipient as an EX type. This is the real cause for my troubles and the gist of the question at hand. – Barok Dec 14 '18 at 02:52