【问题标题】:How to get sender SMTP email address from MailItem in outlook using python?如何使用 python 从 Outlook 中的 MailItem 获取发件人 SMTP 电子邮件地址?
【发布时间】:2021-03-14 11:11:02
【问题描述】:

我正在尝试使用 Python 和 win32 获取 MailItem 的发件人电子邮件地址,但无论何时找到 Exchange 地址,我都无法获取 SMTP 地址。我尝试了网上所有可用的东西,但它返回一个空字符串。这是我正在使用的代码 sn-p:

if msg.Class == 43:
    if msg.SenderEmailType == 'EX':
      print(msg.Sender.GetExchangeUser().PrimarySmtpAddress)
    else:
      print(msg.SenderEmailAddress)

【问题讨论】:

    标签: python email outlook smtp win32com


    【解决方案1】:

    您可以尝试使用MailItem.PropertyAccessor.GetProperty 读取PidTagSenderSmtpAddress MAPI 属性(DASL 名称http://schemas.microsoft.com/mapi/proptag/0x5D01001F) - 使用OutlookSpy(单击IMessage 按钮)或MFCMAPI 查看消息。

    【讨论】:

    • 使用 OutlookSpy 我已经能够找到我需要的属性,即PidTagSenderSmtpAddress_W(是的,非常接近你提到的)。但是对象和属性是不兼容的。因此,我需要添加一些东西以使该属性兼容。请帮我完成最后一步。
    • GetProperty() 返回泛型object',将其转换为string
    • 我想我应该指定项目本身,而不是 MailItem,在我的情况下,msg
    • 是的。 MailItem 是 COM 对象类名 - docs.microsoft.com/en-us/office/vba/api/outlook.mailitem
    • 目前我在做msg.PropertyAccessor.GetProperty.PidTagSenderSmtpAddress_W,显示的错误是AttributeError: 'function' object has no attribute 'PidTagSenderSmtpAddress_W'。查看错误,我不太相信将 object 转换为 string 会有所帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 2015-10-15
    • 1970-01-01
    相关资源
    最近更新 更多