Wednesday, 1 October 2014

How to read email message from .msg file

For reading the .msg file, I am using python built in library "email". you can read .msg file by below code.

import email
def read_MSG(file):
    email_File = open(file)
    messagedic = email.Message(email_File)
    content_type = messagedic["plain/text"]
    FROM = messagedic["From"]
    TO = messagedic.getaddr("To")
    sujet = messagedic["Subject"]
    email_File.close()
    return content_type, FROM, TO, sujet
myMSG= read_MSG("client.msg")
print myMSG

Thank you guys for your support.