print (msg.SenderName)
print (msg.SenderEmailAddress)
print (msg.SentOn)
print (msg.To)
print (msg.CC)
print (msg.BCC)
print (msg.Subject)
print (msg.Body)
I am simply trying to take the above, and write the contents into a newly created .PDF file... So, creating a .PDF file with the contents that I am capturing above.
Below is the full code, where I am opening the .msg
file and extracting it's contents... It's opening the .msg
file, and outputting the contents correctly into the Anaconda prompt window; just have yet to figure out how to push that into a newly created .pdf file with Python.
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem(r"C:\Users\path\path\test_msg.msg")
print (msg.SenderName)
print (msg.SenderEmailAddress)
print (msg.SentOn)
print (msg.To)
print (msg.CC)
print (msg.BCC)
print (msg.Subject)
print (msg.Body)
count_attachments = msg.Attachments.Count
if count_attachments > 0:
for item in range(count_attachments):
print (msg.Attachments.Item)(item + 1).Filename
del outlook, msg