How to process emails with attachment using Python?

Viewed 136

My ultimate goal is to open files that are sent to an email account, process data in those files and upload the data into a database. I am stuck at the first stage. I can't open and process the email message from Outlook. I've never worked with emails programmatically, so my understanding of email data structures is very poor.

I saved an email from MS Outlook containing some text and an attachment on a drive. Then I tried opening it using Python 2.7:

import email
msg = email.message_from_file(open('test with attachment.msg'))
print msg.is_multipart()

is_mulitipart returns False

msg.get_payload() returns blank.

What am I doing wrong? Shouldn't it be a multipart message with text? How should I process this email?

Any help would be greatly appreciated. Thanks!

0 Answers
Related