prefect-email
The prefect-email
library helps you send emails from your Prefect flows.
Getting started
Prerequisites
- 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
The following command will install a version of prefect-email compatible with your installed version of Prefect. If you don’t already have Prefect installed, it will install the newest version of Prefect as well.
Upgrade to the latest versions of Prefect and prefect-email:
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.
In the examples below you load a credentials block to authenticate with the email server.
Send emails
The code below shows how to send an email using the pre-built email_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!
Resources
Refer to the prefect-email
SDK documentation linked in the sidebar to explore all the capabilities of the prefect-email
library.