在 Python 中使用 Outlook 全局地址列表验证电子邮件地址 [英] Verify Email Address using Outlook Global Address List in Python

查看:151
本文介绍了在 Python 中使用 Outlook 全局地址列表验证电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据 Outlook 全局地址列表验证内部电子邮件地址是否有效,并发现了这种方法 这里 我使用的代码如下:

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

然而,我遇到的问题是recipient.Resolved"的值是不正确的.似乎一直返回 True,即使我使用无效地址进行测试.例如,如果我在 Outlook 中输入随机的内部电子邮件地址并按Ctrl+K"要解决它,我会收到错误消息我们将无法发送此邮件,因为电子邮件地址不再有效".但是使用上面的代码,地址是可以解析的.有谁知道如何使用 Outlook 获得完全相同的结果?

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.

推荐答案

如果您的字符串看起来像 SMTP 地址,Outlook 会将其解析为一次性 SMTP 地址.提示我们将无法发送此邮件,因为电子邮件地址不再有效"来自 EWS API(MailTips 命令).

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

您可以检查返回的 Recipient.AddressEntry.Type == "EX" 是否为 GAL 条目.如果您传递 GAL 中不存在的任何其他 SMTP 地址,则地址类型将为SMTP".

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

这篇关于在 Python 中使用 Outlook 全局地址列表验证电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆