Warm tip: This article is reproduced from serverfault.com, please click

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

发布于 2020-12-02 13:25:48

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)
Questioner
Pranayan Metiya
Viewed
0
Dmitry Streblechenko 2020-12-02 23:43:19

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.