Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 10, 2022 06:24
Show Gist options
  • Save aspose-com-gists/971f68115475795758003fdd3ebc579d to your computer and use it in GitHub Desktop.
Save aspose-com-gists/971f68115475795758003fdd3ebc579d to your computer and use it in GitHub Desktop.
# connect to mail server using IMAP
client = ImapClient("imap.gmail.com", 993, "username", "password")
# select folder
client.select_folder("Inbox")
# loop through email messages and save them as .eml files
for msg in client.list_messages():
print("Subject: " + msg.subject)
print("HtmlBody: " + msg.html_body)
print("TextBody: " + msg.body)
client.save_message(msg.unique_id, msg.unique_id + "_out.eml")
# create POP3 client
client = Pop3Client("pop.gmail.com", 995, "username", "password")
# set security options
client.security_options = SecurityOptions.AUTO
# get message count
messageCount = client.get_message_count()
print("Total messages: " + str(messageCount))
# create an instance of the MailMessage class to read message
for i in range(0,messageCount):
message = client.fetch_message(i+1)
print("From:" + str(message.from_address))
print("Subject:" + message.subject)
print(message.html_body)
@aspose-com-gists
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment