prefect-email
library helps you send emails from your Prefect flows.
Getting Started
Prerequisites
- Prefect installed in a virtual environment.
- Many email services, such as 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.
Install prefect-email
Install or update to the latest version of the prefect-email library and dependencies.Register newly installed block types
Register the block types in the prefect-email module to make them available for use.Save credentials to an EmailServerCredentials block
Save your email credentials to a block. Replace the placeholders with your email address and password.Send emails
The code below shows how to send an email using the pre-builtemail_send_message
task.
Capture exceptions and send an email
This example demonstrates how to send an email notification with the details of the exception when a flow run fails.prefect-email
can be wrapped in an except
statement to do just that!