1
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
Dr Upvote
  • 8,023
  • 24
  • 91
  • 204
  • You'll need to find a third-party module that supports the creation of pdf files and install it. There are a number of popular ones, but asking for software recommendations is off-topic here. – martineau Jun 24 '19 at 17:51

0 Answers0