Package: independentsoft.msg
independetsoft.msgMicrosoft Outlook .msg file module for Python. Use this module to easy create, read, update and parse Outlook message files.FeaturesCreate message, appointment, task, contact or any other Outlook item.Read any Outlook .msg file and get all properties.Convert from Outlook message (.msg file) to MIME message (.eml file)Convert from MIME message (.eml file) to Outlook message (.msg file)Set/Get MAPI properties.Set/Get named properties.Add attachments.Read attachments.Save attachments.Add embedded messages.Read embedded messages.Save embedded messages.Examples**********************************************************************************************************************************Createmessagewithplaintextbody,setsomepropertiesandrecipients.**********************************************************************************************************************************fromindependentsoft.msgimportMessagefromindependentsoft.msgimportRecipientfromindependentsoft.msgimportObjectTypefromindependentsoft.msgimportDisplayTypefromindependentsoft.msgimportRecipientTypefromindependentsoft.msgimportMessageFlagfromindependentsoft.msgimportStoreSupportMaskmessage=Message()recipient1=Recipient()recipient1.address_type="SMTP"recipient1.display_type=DisplayType.MAIL_USERrecipient1.object_type=ObjectType.MAIL_USERrecipient1.display_name="John Smith"recipient1.email_address="John@domain.com"recipient1.recipient_type=RecipientType.TOrecipient2=Recipient()recipient2.address_type="SMTP"recipient2.display_type=DisplayType.MAIL_USERrecipient2.object_type=ObjectType.MAIL_USERrecipient2.display_name="Mary Smith"recipient2.email_address="Mary@domain.com"recipient2.recipient_type=RecipientType.CCmessage.subject="Test"message.body="Body text"message.display_to="John Smith"message.display_cc="Mary Smith"message.recipients.append(recipient1)message.recipients.append(recipient2)message.message_flags.append(MessageFlag.UNSENT)message.store_support_masks.append(StoreSupportMask.CREATE)message.save("e:\\output.msg")**********************************************************************************************************************************CreatemessagewithHTMLandRTFbody.OutlookrequiresRTFbodytobesetifHTMLispresentinordertodisplayrichbodytext.**********************************************************************************************************************************fromindependentsoft.msgimportMessagefromindependentsoft.msgimportRecipientfromindependentsoft.msgimportObjectTypefromindependentsoft.msgimportDisplayTypefromindependentsoft.msgimportRecipientTypefromindependentsoft.msgimportMessageFlagfromindependentsoft.msgimportStoreSupportMaskmessage=Message()recipient1=Recipient()recipient1.address_type="SMTP"recipient1.display_type=DisplayType.MAIL_USERrecipient1.object_type=ObjectType.MAIL_USERrecipient1.display_name="John Smith"recipient1.email_address="John@domain.com"recipient1.recipient_type=RecipientType.TOrecipient2=Recipient()recipient2.address_type="SMTP"recipient2.display_type=DisplayType.MAIL_USERrecipient2.object_type=ObjectType.MAIL_USERrecipient2.display_name="Mary Smith"recipient2.email_address="Mary@domain.com"recipient2.recipient_type=RecipientType.CChtml_body="<html><body><b>Hello World bold html text</b></body></html>"html_body_with_rtf="{\\rtf1\\ansi\\ansicpg1252\\fromhtml1\\htmlrtf0 "+html_body+"}"rtf_body=html_body_with_rtf.encode("utf_8")message.subject="Test"message.display_to="John Smith"message.display_cc="Mary Smith"message.recipients.append(recipient1)message.recipients.append(recipient2)message.body_html_text=html_bodymessage.body_rtf=rtf_bodymessage.message_flags.append(MessageFlag.UNSENT)message.store_support_masks.append(StoreSupportMask.CREATE)message.save("e:\\output.msg")**********************************************************************************************************************************Createmessagewithattachment**********************************************************************************************************************************fromindependentsoft.msgimportMessagefromindependentsoft.msgimportAttachmentfromindependentsoft.msgimportRecipientfromindependentsoft.msgimportObjectTypefromindependentsoft.msgimportDisplayTypefromindependentsoft.msgimportRecipientTypefromindependentsoft.msgimportMessageFlagfromindependentsoft.msgimportStoreSupportMaskmessage=Message()recipient1=Recipient()recipient1.address_type="SMTP"recipient1.display_type=DisplayType.MAIL_USERrecipient1.object_type=ObjectType.MAIL_USERrecipient1.display_name="John Smith"recipient1.email_address="John@domain.com"recipient1.recipient_type=RecipientType.TOrecipient2=Recipient()recipient2.address_type="SMTP"recipient2.display_type=DisplayType.MAIL_USERrecipient2.object_type=ObjectType.MAIL_USERrecipient2.display_name="Mary Smith"recipient2.email_address="Mary@domain.com"recipient2.recipient_type=RecipientType.CCmessage.subject="Test"message.body="Body text"message.display_to="John Smith"message.display_cc="Mary Smith"message.recipients.append(recipient1)message.recipients.append(recipient2)message.message_flags.append(MessageFlag.UNSENT)message.store_support_masks.append(StoreSupportMask.CREATE)attachment=Attachment(file_path="e:\\test.pdf")message.attachments.append(attachment)message.save("e:\\output.msg")**********************************************************************************************************************************Readmessageandsaveattachmentstofilesystem**********************************************************************************************************************************fromindependentsoft.msgimportMessagefromindependentsoft.msgimportAttachmentmessage=Message(file_path="e:\\intvalue.msg")foriinrange(len(message.attachments)):attachment=message.attachments[i]attachment.save("e:\\"+str(attachment.file_name))**********************************************************************************************************************************Createappointment**********************************************************************************************************************************importdatetimefromindependentsoft.msgimportMessageappointment=Message()appointment.message_class="IPM.Appointment"appointment.subject="Test"appointment.body="Body text"appointment.location="My Office"appointment.appointment_start_time=datetime.datetime(2019,12,10,8,0,0)appointment.appointment_end_time=datetime.datetime(2019,12,10,10,0,0)appointment.save("e:\\appointment.msg")**********************************************************************************************************************************Createcontact**********************************************************************************************************************************importdatetimefromindependentsoft.msgimportMessagecontact=Message()contact.message_class="IPM.Contact"contact.subject="John Smith"contact.display_name_prefix="Mr."contact.display_name="John Smith"contact.given_name="John"contact.surname="Smith"contact.company_name="Independentsoft"contact.email1_address="john@independentsoft.com"contact.email1_display_as="John"contact.email1_display_name="John"contact.email1_type="SMTP"contact.business_address_city="NY"contact.business_address_street="First Street"contact.business_address_country="USA"contact.business_address="First Street, NY, USA"contact.business_phone="555-666-777"contact.save("e:\\contact.msg")**********************************************************************************************************************************Createtask**********************************************************************************************************************************importdatetimefromindependentsoft.msgimportMessagefromindependentsoft.msgimportPriorityfromindependentsoft.msgimportTaskStatustask=Message()task.message_class="IPM.Task"task.subject="Test"task.body="Body text"task.owner="John"task.task_status=TaskStatus.NOT_STARTEDtask.priority=Priority.HIGHtask.task_start_date=datetime.datetime(2019,12,20,10,0,0)task.task_due_date=datetime.datetime(2019,12,22,10,0,0)task.save("e:\\task.msg")**********************************************************************************************************************************Createnote**********************************************************************************************************************************importdatetimefromindependentsoft.msgimportMessagefromindependentsoft.msgimportNoteColornote=Message()note.message_class="IPM.StickyNote"note.subject="Test"note.body="Body text"note.note_color=NoteColor.GREENnote.note_top=200note.note_left=300note.note_height=200note.note_width=250note.save("e:\\note.msg")