The goal here is to make it as simple and painless as possible to send emails using asyncio.
In the end, your code will look something like this:
import asyncio
from aioyagmail import AIOSMTP
loop = asyncio.get_event_loop()
async def send_single():
# walks you through oauth2 process if no file at this location
async with AIOSMTP(oauth2_file="~/oauth2_gmail.json") as yag:
await yag.send(to="[email protected]", subject="hi")
async def send_multi():
async with AIOSMTP(oauth2_file="~/oauth2_gmail.json") as yag:
# Runs asynchronously!
await asyncio.gather(yag.send(subject="1"),
yag.send(subject="2"),
yag.send(subject="3"))
loop.run_until_complete(send_single())
loop.run_until_complete(send_multi())
It is possible like in yagmail
to use username and password, but this is not actively encouraged anymore.
See https://github.com/kootenpv/yagmail#username-and-password how to do it.
Have a look at yagmail
. Any issue NOT related to async should be posted there (or found out about).
Watch out that gmail does not block you for spamming. Using async you could potentially be sending emails too rapidly.
If you like aioyagmail
, feel free (no pun intended) to donate any amount you'd like :-)