How to perform operations on emails and folders using imap_tools?

 IMAP_TOOLS: imap_tools is a library used to perform operations on emails and folders.

Installation: pip install imap-tools

How to log in to the mail? 

We need to pass the username and password to the login function. And also we can pass the initial_folder name.



How to get subjects from a specific folder? 

 First searches email nums by criteria in the current folder, then fetch and yields.


E-mail attributes: 
You can fetch the required data of e-mail using email attributes. Like you can fetch sender of mail using from_ attribute. You can easily fetch the date of mail using date attributes.  There are lots of e-mail attributes, we see some of them.


Search criteria: You can use three approaches to build search criteria. 
  1. Search using subject.
  2. Search using text.
  3. Search using charset.

AND, OR, NOT, Header and UidRange these classes are used for search logic.


How to perform actions on email?

You can perform the following operations on email:
  1.  copy
  2. move
  3. delete
  4. flag
  5. append


How to perform actions on folders?

There are many actions you can perform on the folder using imap_tools, like create, rename, delete, the status of the folder, and many more.


How to fetch unseen messages information?

To fetch unseen or seen mails from inbox, you just need to add seen key in the fetch () method. 

Get unread mail list:


Get read mail list: 

IMAP provides lots of keys:



Conclusion: In this article, we learn about the imap_tools library. And how to perform operations on mails and folders.

For more information regarding IMAP_TOOLS, please click on the below link.

https://pypi.org/project/imap-tools/

Thank you for reading... 😊


Comments

Popular posts from this blog

How to convert PDF file into audio file?

Pillow Libary in Python.