def run():

    dataDir = "Data/"
    #ExStart: SaveMessageAsHTML
    # Load file
    message = MailMessage.load(dataDir + "Message.eml")

    message.save(dataDir + "SaveAsHTML_out.html", SaveOptions.DefaultHtml)

    #OR

    eml = MailMessage.load(dataDir + "Message.eml")
    options = SaveOptions.default_html
    options.embed_resources = False
    options.HtmlFormatOptions = HtmlFormatOptions.WriteHeader | HtmlFormatOptions.WriteCompleteEmailAddress  #save the message headers to output HTML using the formatting options
    eml.save(dataDir + "SaveAsHTML1_out.html", options)
Exemple #2
0
def run():
    dataDir = "Data/"
    #ExStart: SetBodyCompression
    eml = MailMessage.load(dataDir +
                           "CreatingAndSavingOutlookMessages_out.msg")
    options = MapiConversionOptions()
    options.use_body_compression = True
    ae_mapi = MapiMessage.from_mail_message(eml, options)
def run():

    dataDir = "Data/"
    #ExStart: GetDecodedHeaderValues
    mailMessage = MailMessage.load(dataDir + "emlWithHeaders.eml")

    decodedValue = mailMessage.headers.get_decoded_value("Thread-Topic")

    print(decodedValue)
def run():
    dataDir = "Data/"
    #ExStart: ExtractEmbeddedObjectsFromEmail
    # Create an instance of MailMessage class
    message = MailMessage.load(dataDir + "EmailWithAttandEmbedded.eml")

    # Save attachments from message
    for index, att in enumerate(message.attachments):
        att.save(dataDir + att.name)
def run():

    dataDir = "Data/"
    #ExStart: SaveMailMessageAsMHTML
    # Load file
    eml = MailMessage.load(dataDir + "Message.eml")

    eml.save(Path.Combine(dataDir, "outTest_out.msg"),
             SaveOptions.default_mhtml)
def run():
    dataDir = "Data/"
    #ExStart: RetrievContentDescriptionFromAttachment
    # Create an instance of MailMessage class
    message = MailMessage.load(dataDir + "EmailWithAttandEmbedded.eml")

    # Save attachments from message
    for index, att in enumerate(message.attachments):
        print(att.headers.get("Content-Description"))
Exemple #7
0
def run():

    dataDir = "Data/"
    #ExStart: ReadMessageByPreservingTNEFAttachment
    options = MsgLoadOptions()
    options.preserve_tnef_attachments = True
    eml = MailMessage.load(dataDir + "EmbeddedImage1.msg", options)
    for attachment in eml.Attachments:
        print(attachment.name)
def run():
    dataDir = "Data/"
    #ExStart: DisplayAttachmentFileName
    # Create an instance of MailMessage class
    message = MailMessage.load(dataDir + "EmailWithAttandEmbedded.eml")

    # Print attachments information
    for index, att in enumerate(message.attachments):
        print(att.name)
def run():
    dataDir = "Data/"
    #ExStart: ForwardEmail
    eml = MailMessage.load(dataDir + "Message.eml")
    eml.from_address = "*****@*****.**"

    #Send using Smtp Client
    client = SmtpClient("smtp.gmail.com", 995, "username", "password")
    client.security_options = SecurityOptions.AUTO
    client.forward("*****@*****.**", "*****@*****.**", eml)
def run():
    dataDir = "Data/"
    #ExStart: RemoveLRTracesFromMessageBody
    # Create an instance of MailMessage class
    message = MailMessage.load(dataDir + "EmailWithAttandEmbedded.eml")

    message.linked_resources.remove_at(0, True)

    message.alternate_views[0].linked_resources.clear(True)

    message.save(dataDir + "RemoveLRTracesFromMessageBody_out.eml")
Exemple #11
0
def run():
    
    dataDir = "Data/"
    #ExStart: ConvertToMHTMLWithoutInlineImages
    # Load file
    eml = MailMessage.load(dataDir + "Message.eml")

    options = MhtSaveOptions()
    options.skip_inline_images = True

    eml.save(Path.Combine(dataDir, "outTest_out.msg"), SaveOptions.default_mhtml)
Exemple #12
0
def run():
	dataDir = "Data/"
	#ExStart: PreservingEmbeddedMsgFormat
	eml =  MailMessage.load(dataDir + "sample.eml", EmlLoadOptions())

	options = MapiConversionOptions.unicode_format

	options.preserve_embedded_message_format = True

	# Create an instance of the MapiMessage class and pass MailMessage as argument
	outlookMsg = MapiMessage.from_mail_message(eml, options)
Exemple #13
0
def run():
    dataDir = "Data/"
    #ExStart: ExtractingEmailHeaders
    # Create MailMessage instance by loading an EML file
    message = MailMessage.load(dataDir + "email-headers.eml")
    print("\n\nheaders:\n\n")

    # Print out all the headers
    index = 0
    for index, header in enumerate(message.headers):
        print(header + " - ", end=" ")
        print(message.headers.get(index))
def run():
    dataDir = "Data/"
    #ExStart: DetermineAttachmendEmbeddedMessage
    # Create an instance of MailMessage class
    message = MailMessage.load(dataDir + "EmailWithAttandEmbedded.eml")

    # Save attachments from message
    for index, att in enumerate(message.attachments):
        if att.is_embedded_message:
            print("Attachment is an embedded message")
        else:
            print("Attachment is not an embedded message")
Exemple #15
0
def run():
    dataDir = ""
    #ExStart: DisplayEmailInformation
    # Create MailMessage instance by loading an Eml file
    message = MailMessage.load(dataDir + "test.eml")

    # Gets the sender info, recipient info, Subject, htmlbody and textbody
    print("Subject: " + message.subject)

    print("HtmlBody: " + message.html_body)

    print("TextBody: " + message.body)
def run():

    dataDir = "Data/"
    #ExStart: PreserveTnefAttachment
    # Load file
    mailMessage = MailMessage.load(dataDir + "PreserveOriginalBoundaries.eml")

    # Save as eml with preserved attachment
    emlSaveOptions = EmlSaveOptions(MailMessageSaveType.EmlFormat)
    emlSaveOptions.file_compatibility_mode = FileCompatibilityMode.PreserveTnefAttachments

    mailMessage.save(dataDir + "PreserveTNEFAttachment_out.eml",
                     emlSaveOptions)
Exemple #17
0
def run():

    dataDir = "Data/"
    #ExStart: PreserveOriginalBoundaries
    # Load file
    mailMessage = MailMessage.load(dataDir + "Attachments.eml")

    # Save as eml with preserved original boundares
    emlSaveOptions = EmlSaveOptions(MailMessageSaveType.EmlFormat)
    emlSaveOptions.preserve_original_boundaries = True

    mailMessage.save(dataDir + "PreserveOriginalBoundaries_out.eml",
                     emlSaveOptions)
def run():

    dataDir = "Data/"
    #ExStart: SavingMSGWithPreservedDates
    # Load file
    eml = MailMessage.load(dataDir + "Message.eml")

    # Save as msg with preserved dates
    msgSaveOptions = MsgSaveOptions(
        MailMessageSaveType.OutlookMessageFormatUnicode)
    msgSaveOptions.PreserveOriginalDates = True

    eml.save(Path.Combine(dataDir, "outTest_out.msg"), msgSaveOptions)
def run():

    dataDir = "Data/"
    #ExStart: PreserveEmbeddedMSGFormatDuringLoad
    # Load file
    emlLoadOptions = EmlLoadOptions()
    emlLoadOptions.preserve_embedded_message_format = True

    mail = MailMessage.load(dataDir + "tnefWithMsgInside.eml", emlLoadOptions)

    stream = mail.attachments[0].content_stream

    fileFormat = FileFormatUtil.detect_file_format(stream).FileFormatType

    Console.WriteLine("Embedded message file format: " + fileFormat)
Exemple #20
0
def run():

    dataDir = "Data/"
    #ExStart: LoadMessageWithLoadOptions
    # Load Eml, html, mhtml, msg and dat file
    mailMessage = MailMessage.load(dataDir + "Message.eml", EmlLoadOptions())
    MailMessage.load(dataDir + "description.html", HtmlLoadOptions())
    MailMessage.load(dataDir + "Message.mhtml", MhtmlLoadOptions())
    MailMessage.load(dataDir + "Message.msg", MsgLoadOptions())

    # loading with custom options
    emlLoadOptions = EmlLoadOptions()
    emlLoadOptions.preserve_tnef_attachments = True

    MailMessage.load(dataDir + "description.html", emlLoadOptions)
    htmlLoadOptions = HtmlLoadOptions()
    htmlLoadOptions.should_add_plain_text_view = True
    htmlLoadOptions.path_to_resources = dataDir

    MailMessage.load(dataDir + "description.html", emlLoadOptions)