Level of Difficulty: Beginner – Senior.
Have you ever had a use case where you have a shared mailbox setup on your Outlook but you don’t have the credentials to the account behind the mailbox (if one exists)? Well you can get around that by running the Python script detailed in this post.
The approach to this solution is to use Outlook, which should already be set up on your computer, with Python to pull a list of email addresses of senders and write it to Excel.
For this, you’ll need to install the Pandas library, only if you want to write the addresses and display names to Excel:
import win32com.client import pandas as pd # Outlook Connection outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") folder = outlook.Folders.Item("@<Mailbox Name>") inbox = folder.Folders.Item("Inbox") messages = inbox.Items # Initialise Lists senders =  addresses =  # Iterate through messages for sender name and address for message in messages: try: if message.Class==43: if message.SenderEmailType=='EX': if message.Sender.GetExchangeUser() != None: addresses.append(message.Sender.GetExchangeUser().PrimarySmtpAddress) else: addresses.append(message.Sender.GetExchangeDistributionList().PrimarySmtpAddress) else: addresses.append(message.SenderEmailAddress) senders.append(message.Sender) except Exception as e: print(e) # Create Excel file with results df = pd.DataFrame() df['Sender'] = senders df['Address'] = addresses df.to_excel('Addresses.xlsx')
Did this work for you? Feel free to drop a comment below with suggestions or questions.