Verify Email Address using Outlook Global Address List in Python

别等时光非礼了梦想. 提交于 2020-06-28 05:42:37

问题


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.


回答1:


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".



来源:https://stackoverflow.com/questions/43420378/verify-email-address-using-outlook-global-address-list-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!