简体   繁体   中英

How to get sender SMTP email address from MailItem in outlook using python?

I am trying to get the sender email address of MailItem using Python and win32, but whenever Exchange address is found, I am unable to get the SMTP address. I tried everything available on the net, but it is returning an empty string. Here is the code snippet I'm using:

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

You can try to read PidTagSenderSmtpAddress MAPI property (DASL name http://schemas.microsoft.com/mapi/proptag/0x5D01001F ) using MailItem.PropertyAccessor.GetProperty - take a look at the message with OutlookSpy (click IMessage button) or MFCMAPI .

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