コード例 #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():
    #ExStart: ListingMessagesWithPagingSupport
    conn = ImapClient("imap.gmail.com", 993, "username", "password")
    conn.select_folder("Inbox")
    for msg in conn.list_messages():
        print("From: '{}', MIME Id: {}".format(msg.from_address,
                                               msg.message_id))
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))
コード例 #4
0
def run():
    dataDir = ""

    #ExStart: RetrievingServerExtensions
    client = ImapClient("imap.gmail.com", 993, "username", "password")
    capabilities = client.get_capabilities()
    for val in capabilities:
        print(val)
コード例 #5
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"))
コード例 #6
0
def run():
    dataDir = ""

    #ExStart: FetchEmailMessageFromServer
    client = ImapClient("imap.gmail.com", 993, "username", "password")
    client.select_folder("Inbox")
    builder = ImapQueryBuilder()
    builder.subject.contains("Newsletter")
    builder.internal_date.on(dt.datetime.now())
    query = builder.get_query()
    msgsColl = client.list_messages(query)
    print("Total Messages fulfilling search criterion: " + str(len(msgsColl)))
コード例 #7
0
def run():
    dataDir = ""

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

    #Iterate through the collection to get folder info one by one
    for folderInfo in folderInfoColl:
        print("Folder name is " + folderInfo.name)
    folderExtInfo = client.get_folder_info(folderInfo.name)
    print("New message count: " + str(folderExtInfo.new_message_count))
    print("Is it readonly? " + str(folderExtInfo.read_only))
    print("Total number of messages " + str(folderExtInfo.total_message_count))
コード例 #8
0
def run():

    #ExStart: SettingMessageFlags
    conn = ImapClient("imap.gmail.com", 993, "username", "password")
    conn.select_folder("Inbox")
    conn.change_message_flags(1, ImapMessageFlags.is_read)

    conn.remove_message_flags(1, ImapMessageFlags.is_read)
コード例 #9
0
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)
コード例 #10
0
def run():
    dataDir = ""

    try:
        #ExStart:CaseSensitiveEmailsFiltering
        client = ImapClient("imap.gmail.com", 993, "username", "password")
        client.select_folder("Inbox")
        builder = ImapQueryBuilder()
        builder.subject.contains("Newsletter", True)

        query = builder.get_query()
        msgsColl = client.list_messages(query)
        print("Total Messages fulfilling search criterion: " +
              str(len(msgsColl)))
        #ExEnd:CaseSensitiveEmailsFiltering
    except Exception as ex:
        print(str(ex))
コード例 #11
0
def run():
    dataDir = ""

    #ExStart: FetchEmailMessageFromServer
    conn = ImapClient("imap.gmail.com", 993, "username", "password")
    conn.select_folder("Inbox")
    for msg in conn.list_messages():
        conn.save_message(msg.unique_id, dataDir + msg.unique_id + "_out.eml")
def run():
    dataDir = ""

    #ExStart: SavingMessageFromIMAPServer
    conn = ImapClient("imap.gmail.com", 993, "username", "password")
    conn.select_folder("Inbox")
    for msgInfo in conn.list_messages():
        msg = conn.fetch_message(msgInfo.unique_id)
        msg.save(dataDir + msgInfo.unique_id + "_out.msg",
                 aspose.email.SaveOptions.default_msg_unicode)
コード例 #13
0
def run():

    dataDir = ""

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

    #Append a new Message to Inbox
    msg = MailMessage("*****@*****.**", "*****@*****.**", "subject",
                      "message")
    msgId = client.append_message(msg)

    #List messages from Inbox
    msgsCollection = client.list_messages()
    print("Total Messages in Inbox: " + str(len(msgsCollection)))

    #Move message to another folder
    client.move_message(msgId, folderName)

    #List messages from Inbox
    msgsCollection = client.list_messages()
    print("Total Messages in Inbox: " + str(len(msgsCollection)))
コード例 #14
0
def run():
    dataDir = ""

    #ExStart: ListingMessagesWithPagingSupport
    client = ImapClient("imap.gmail.com", 993, "username", "password")
    client.select_folder("Inbox")
    pages = []
    itemsPerPage = 1
    pageInfo = client.list_messages_by_page(itemsPerPage)
    print(pageInfo.total_count)
    pages.append(pageInfo)

    while not pageInfo.last_page:
        pageInfo = client.list_messages_by_page(pageInfo.next_page)
        pages.append(pageInfo)

    retrievedItems = 0
    for folderCol in pages:
        retrievedItems += len(folderCol.items)

    print(str(retrievedItems))
コード例 #15
0
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)))
コード例 #16
0
def run():
    #ExStart: ListingMessagesRecursively
    conn = ImapClient("imap.gmail.com", 993, "username", "password")
    conn.select_folder("Inbox")
    msgsColl = conn.list_messages(True)
    print("Total Messages: " + str(len(msgsColl)))
コード例 #17
0
def run():
    #ExStart: SSLEnabledIMAPServer
    client = ImapClient("imap.domain.com", 993, "*****@*****.**", "pwd")
    client.security_options = SecurityOptions.SSLIMPLICIT
コード例 #18
0
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)))