Learn how to read emails from email server via IMAP in Python: https://blog.aspose.com/2021/12/17/read-emails-using-imap-in-python/
Last active
December 17, 2021 13:31
-
-
Save aspose-com-gists/9132c041d110e75d026870a96a08b189 to your computer and use it in GitHub Desktop.
Read Emails from Email Server using IMAP in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.email import SecurityOptions, ImapClient | |
# create an instance of ImapClient and provide host, port, username and password | |
client = ImapClient("imap.domain.com", 993, "user@domain.com", "password") | |
# set security options | |
client.security_options = SecurityOptions.SSLIMPLICIT | |
# use ImapClient object to access mailbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.email import ImapClient | |
# create an instance of ImapClient and provide host, port, username and password | |
with ImapClient("imap.gmail.com", 993, "username", "password") as client: | |
# get list of folders | |
folderInfoColl = client.list_folders() | |
# iterate through the collection to get folders' 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)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.email import ImapClient | |
# create an instance of ImapClient and provide host, port, username and password | |
with ImapClient("imap.gmail.com", 993, "username", "password") as client: | |
# select folder | |
client.select_folder("Inbox") | |
# read each message in collection | |
for msg in client.list_messages(): | |
print( "From: '{}', MIME Id: {}".format(msg.from_address, msg.message_id) ) | |
# save message on disk | |
client.save_message(msg.unique_id, msg.unique_id + "_out.eml") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.email import ImapClient | |
# create an instance of ImapClient and provide host, port, username and password | |
with ImapClient("imap.gmail.com", 993, "username", "password") as client: | |
# select the folder from mailbox | |
client.select_folder("Inbox") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment