prefect-email is a collection of prebuilt Prefect tasks that can be used to quickly construct Prefect flows that interacts with email services.
Requires an installation of Python 3.7+.
We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.
These tasks are designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the Prefect documentation.
pip install prefect-email
Then, register to view the block on Prefect Cloud:
prefect block register -m prefect_email
Send an email using Gmail
from prefect import flow from prefect_email import EmailServerCredentials, email_send_message @flow def example_email_send_message_flow(): email_server_credentials = EmailServerCredentials( username="firstname.lastname@example.org", password="MUST_be_an_app_password_here!", ) subject = email_send_message( email_server_credentials=email_server_credentials, subject="Example Flow Notification using Gmail", msg="This proves email_send_message works!", email_to="email@example.com", ) return subject example_email_send_message_flow()
Please note, many email services, like Gmail, require an App Password to successfully send emails. If you encounter an error similar to
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted..., it's likely you are not using an App Password.
If you encounter any bugs while using
prefect-email, feel free to open an issue in the prefect-email repository.
Feel free to ⭐️ or watch
prefect-email for updates too!
If you'd like to install a version of
prefect-email for development, clone the repository and perform an editable install with
git clone https://github.com/PrefectHQ/prefect-email.git cd prefect-email/ pip install -e ".[dev]" # Install linting pre-commit hooks pre-commit install