I was looking for an asynchronous library for imap and I found this library called imap_tools
and find it very easy to use and really want to stick with it but its not asynchronous. The reason I want it to be asynchronous is because I want to use it inside discord.py
and non-async network operations would block the event loop and especially because sometimes the response takes longer or gets stuck or anything like that and affects the performance of my bot.
Is there anything I can do to use this library in asynchronous manner like I just need to connect with imap server and fetch an email and that's it. Is it possible that I can just wrap that functionality in an async function?
from imap_tools import MailBox, AND
import asyncio
async def fetch_emails():
with MailBox('imap.gmail.com').login('username@gmail.com', 'pwd') as mailbox:
for msg in mailbox.fetch():
print(msg.subject)
asyncio.run(fetch_emails())