简体   繁体   中英

Verify Email Address using Outlook Global Address List in Python

I am trying to verify if internal email address is valid based upon Outlook Global Address List and found out this approach here The code I am using is as follows:

outlook = win32com.client.gencache.EnsureDispatch('Outlook.Application')
recipient = outlook.Session.CreateRecipient(emailToValidate)
recipient.Resolve()
print recipient.Resolved

However, the issue I ran into is that the value of "recipient.Resolved" seems to return True all the time, even if I tested with invalid address. For example, if I typed random internal email address in Outlook and press "Ctrl+K" to resolve it, I will get the error "We won't be able to deliver this message because email address is no longer valid" but using the code above, the address is resolvable. Does anyone know how I can get exact same results with Outlook?

And I am also thinking to communicate with internal mail server to verify email addresses but do not really want to put my cleartext credentials in the script, does anyone have advice about that? Thanks and any help is appreciated.

If your string looks like an SMTP address, Outlook will resolve it as a one-off SMTP address. The prompt "We won't be able to deliver this message because email address is no longer valid" comes from the EWS API (MailTips command).

You can check if the returned Recipient.AddressEntry.Type == "EX" for a GAL entry. If you pass any other SMTP address not present in GAL, the address type will "SMTP".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM