Пример #1
0
def run():
    dataDir = ""

    #ExStart: CopyMessageToAnotherFolder
    client = ImapClient("imap.gmail.com", 993, "username", "password")
    client.select_folder("Inbox")
    folderName = "MovedMessagesToFolder"

    #List messages from Inbox to verify that messages have been copied
    msgsCollection = client.list_messages()
    print("Total Messages in Inbox before appending: " + str(len(msgsCollection)))

    #Append 2 new Messages to Inbox
    msg = MailMessage("*****@*****.**", "*****@*****.**", "Message1TobeMoved", "message")
    msgId1 = client.append_message(msg)
    msg2 = MailMessage("*****@*****.**", "*****@*****.**", "Message1TobeMoved", "message")
    msgId2 = client.append_message(msg2)

    #List messages from Inbox to verify that messages have been copied
    msgsCollection = client.list_messages()
    print("Total Messages in Inbox after appending: " + str(len(msgsCollection)))

    msgsIds = []
    msgsIds.append(msgId1)
    msgsIds.append(msgId2)

    #Copy message to another folder
    client.copy_messages(msgsIds, folderName)
def run():
    dataDir = ""

    #ExStart: DeleteMultipleMessages
    client = ImapClient("imap.gmail.com", 993, "username", "password")

    print(client.uid_plus_supported)

    #Append some test messages
    client.select_folder("Inbox")
    uidList = []

    messageInfoCol = client.list_messages()
    print("Total messages in Inbox before appending: " + str(len(messageInfoCol)))

    #No. of messages to be appended
    messageNumber = 2

    message = MailMessage("*****@*****.**", "*****@*****.**", "Message 1", "Add ability in ImapClient to delete message")
    emailId = client.append_message(message)
    uidList.append(emailId)

    message = MailMessage("*****@*****.**", "*****@*****.**", "Message 2", "Add ability in ImapClient to delete message")
    emailId = client.append_message(message)
    uidList.append(emailId)

    #Now verify that all the messages have been appended to the mailbox
    messageInfoCol = client.list_messages()
    print("Total messages in Inbox after appending: " + str(len(messageInfoCol)))

    client.delete_messages(uidList, True)
    client.commit_deletes()
    messageInfoCol = client.list_messages()
    print("Total messages in Inbox after deletion: " + str(len(messageInfoCol)))
Пример #3
0
def run():
    
    dataDir = "Data/"
    #ExStart: SaveMessageAsOFT
    # Load file
    eml =MailMessage("*****@*****.**", "*****@*****.**", "template subject", "Template body")
    oftEmlFileName = "EmlAsOft_out.oft"
    options = SaveOptions.default_msg_unicode
    options.save_as_template = True
    eml.save(dataDir + oftEmlFileName, options)
def run():
    dataDir = "Data/"
    #ExStart: CreateNewMessagesToThunderbird
    # Initialize MboxStorageWriter and pass the above stream to it
    writer = MboxrdStorageWriter(dataDir + "ExampleMBox_out.mbox", False)
    # Prepare a new message using the MailMessage class
    message = MailMessage("*****@*****.**", "*****@*****.**",
                          "Eml generated for Mbox",
                          "added from Aspose.Email for Python")
    message.is_draft = False
    # Add this message to storage
    writer.write_message(message)
    # Close all related streams
    writer.dispose()
def run():

    dataDir = ""

    #ExStart: DeleteSingleMessage
    client = ImapClient("imap.gmail.com", 993, "username", "password")
    client.select_folder("Inbox")
    message = MailMessage(
        "*****@*****.**", "*****@*****.**",
        "Message deletion using IMAP Client",
        "EMAILNET-35227 Add ability in ImapClient to delete message")

    messageInfoCol = client.list_messages()
    print("Total messages in Inbox before appending: " +
          str(len(messageInfoCol)))

    emailId = client.append_message(message)
    print("Email appended to inbox with email Id: " + emailId)

    # Now verify that all the messages have been appended to the mailbox
    messageInfoCol = client.list_messages()
    print("Total messages in Inbox after appending: " +
          str(len(messageInfoCol)))

    client.delete_message(emailId)
    client.commit_deletes()
    messageInfoCol = client.list_messages()
    print("Total messages in Inbox after deletion: " +
          str(len(messageInfoCol)))
def run():
	dataDir = "Data/"
	
	#ExStart: CreatingMSGFilesWithRtfBody
	eml = MailMessage()
	eml.is_draft = True

	# Create an instance of the MapiMessage class and pass MailMessage as argument
	outlookMsg = MapiMessage.from_mail_message(eml)

	# Set RTF Body
	outlookMsg.body_rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}}\r\n{\\*\\generator Msftedit 5.41.21.2510;}\\viewkind4\\uc1\\pard\\sa200\\sl276\\slmult1\\lang9\\f0\\fs22 This is RTF Body with this \\b bold \\b0 text.\\par\r\n}\r\n\0"
				
	# Save the message (MSG) file
	strMsgFile = "CreatingMSGFilesWithRtfBody_out.msg"
	outlookMsg.save(dataDir + strMsgFile);
def run():

    dataDir = ""

    #ExStart: RetreiveExtraParametersAsSummaryInformation
    client = ImapClient("imap.gmail.com", 993, "username", "password")
    client.select_folder("Inbox")
    msg = MailMessage("*****@*****.**", "*****@*****.**", "subject",
                      "message")
    client.subscribe_folder(client.current_folder.name)
    uid = client.append_message(client.current_folder.name, msg)

    messageExtraFields = ["X-GM-MSGID", "X-GM-THRID"]

    #retreive the message summary information using it's UID
    messageInfoUID = client.list_message(uid, messageExtraFields)

    #retreive the message summary information using it's sequence number
    messageInfoSeqNum = client.list_message(1, messageExtraFields)

    #List messages in general from the server based on the defined properties
    messageInfoCol = client.list_messages(messageExtraFields)

    print(str(len(messageInfoCol)))
    messageInfoFromList = messageInfoCol[0]

    if messageInfoFromList.extra_parameters is not None:
        for paramName in messageExtraFields:
            print(messageInfoFromList.extra_parameters.has_key(paramName))
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)
def run():
    dataDir = "Data/"
    #ExStart:ChangeEmailAddress
    message = MailMessage()

    message.subject = "Creating Message with Friendly Email Address."

    # A To address with a friendly name can also be specified like this
    message.to.append(MailAddress("*****@*****.**", "Kyle Huang"))

    # Specify Cc and Bcc email address along with a friendly name
    message.cc.append(MailAddress("*****@*****.**", "Guangzhou Team"))
    message.bcc.append(MailAddress("*****@*****.**", "Ammad ulHaq "))

    message.save(dataDir + "MessageWithFrienlyName_out.eml",
                 SaveOptions.default_eml)
Пример #10
0
def run():
    dataDir = "Data/"
    #ExStart: CreatingAndSavingOutlookMSG
    eml = MailMessage()

    # Set from, to, subject and body properties
    eml.from_address = "*****@*****.**"
    eml.to.append("*****@*****.**")
    eml.subject = "This is test message"
    eml.body = "This is test body"

    # Create an instance of the MapiMessage class and pass MailMessage as argument
    outlookMsg = MapiMessage.from_mail_message(eml)

    # Save the message (MSG) file
    strMsgFile = "CreatingAndSavingOutlookMessages_out.msg"
    outlookMsg.save(dataDir + strMsgFile)
Пример #11
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: 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: 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: 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"))
Пример #15
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: GetDecodedHeaderValues
    mailMessage = MailMessage.load(dataDir + "emlWithHeaders.eml")

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

    print(decodedValue)
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 = ""
    #ExStart: AppendMessagetoFolder
    client = ImapClient("imap.gmail.com", 993, "username", "password")
    client.select_folder("Inbox")
    msg = MailMessage("*****@*****.**", "*****@*****.**", "subject",
                      "message")
    client.subscribe_folder(client.current_folder.name)
    client.append_message(client.current_folder.name, msg)
Пример #19
0
def run():
    #ExStart: SetCustomFlags
    client = ImapClient("imap.gmail.com", 993, "username", "password")
    message = MailMessage("*****@*****.**", "*****@*****.**", "subject",
                          "message")

    #Append the message to mailbox
    uid = client.append_message("Inbox", message)

    client.add_message_flags(uid, ImapMessageFlags.keyword("custom1"))
def run():
    dataDir = "Data/"
    #ExStart: DraftAppointmentRequest
    #Create Appointment instance
    attendees = MailAddressCollection()
    attendees.append("*****@*****.**")
    app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), "*****@*****.**", attendees);
    app.summary = "Release Meetting";
    app.description = "Discuss for the next release"
    app.method_type = AppointmentMethodType.PUBLISH

    message = MailMessage("*****@*****.**", "*****@*****.**", "", "")

    message.add_alternate_view(app.request_apointment())

    msg = MapiMessage.from_mail_message(message)

    # Save the appointment as draft.
    msg.save(dataDir + "DraftAppointmentRequest_out.msg")
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)
Пример #22
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)
Пример #23
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)
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")
Пример #25
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")
Пример #27
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():
    #ExStart: SendingBulkEmails
    message1 = MailMessage("*****@*****.**", "*****@*****.**",
                           "Sending Bulk Emails using Aspose.Email",
                           "message1, how are you?")
    message2 = MailMessage("*****@*****.**", "*****@*****.**",
                           "Sending Bulk Emails using Aspose.Email",
                           "message2, how are you?")
    message3 = MailMessage("*****@*****.**", "*****@*****.**",
                           "Sending Bulk Emails using Aspose.Email",
                           "message3, how are you?")

    manyMsg = MailMessageCollection()
    manyMsg.append(message1)
    manyMsg.append(message2)
    manyMsg.append(message3)

    #Send using Smtp Client
    client = SmtpClient("smtp.gmail.com", 995, "username", "password")
    client.security_options = SecurityOptions.AUTO

    client.send(manyMsg)
Пример #29
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)