I am programming a script to return each person - along with their department - that was a part of a thread in my Junk folder. As of now I have managed to correctly return their names, however despite trying multiple different methods, I have been unable to access the Departments property.
Here is an example of what I am currently working with:
import win32com.client
output_dir = Path.cwd() / "Output"
output_dir.mkdir(parents=True, exist_ok=True)
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
gal = outlook.Session.GetGlobalAddressList()
entries = gal.AddressEntries
inbox = outlook.GetDefaultFolder(23)
messages = inbox.Items
num = 0
for message in messages:
author = message.SenderName
recipient = outlook.CreateRecipient(f"{message.SenderEmailAddress.partition('-')[2]}@placeholder.com")
recipient.Resolve()
target_folder = output_dir / str(num)
target_folder.mkdir(parents=True, exist_ok=True)
Path(target_folder / "EMAIL_author.txt").write_text(str(message.SenderName))
Path(target_folder / "EMAIL_YEAR.txt").write_text(str(recipient.AddressEntry.GetExchangeUser().GetExchangeUserManager()))
num += 1
Currently working in Python 3.10.8
Any help is appreciated.
source https://stackoverflow.com/questions/74494922/how-could-i-find-the-sender-department-in-microsoft-outlook-using-win32com-in-py
Comments
Post a Comment