Package: prefect-email
prefect-emailVisit the full docshereto see additional examples and the API reference.prefect-emailis a collection of prebuilt Prefect integrations that can be used to interact with email services.Getting StartedIntegrate with Prefect flowsprefect-emailmakes sending emails effortless, giving you peace of mind that your emails are being sent as expected.First, installprefect-emailandsave your email credentials to a blockto run the examples below!fromprefectimportflowfromprefect_emailimportEmailServerCredentials,email_send_message@flowdefexample_email_send_message_flow(email_addresses):email_server_credentials=EmailServerCredentials.load("BLOCK-NAME-PLACEHOLDER")foremail_addressinemail_addresses:subject=email_send_message.with_options(name=f"email{email_address}").submit(email_server_credentials=email_server_credentials,subject="Example Flow Notification using Gmail",msg="This proves email_send_message works!",email_to=email_address,)example_email_send_message_flow(["EMAIL-ADDRESS-PLACEHOLDER"])Outputs:16:58:27.646|INFO|prefect.engine-Createdflowrun'busy-bat'forflow'example-email-send-message-flow'16:58:29.225|INFO|Flowrun'busy-bat'-Createdtaskrun'email someone@gmail.com-0'fortask'email someone@gmail.com'16:58:29.229|INFO|Flowrun'busy-bat'-Submittedtaskrun'email someone@gmail.com-0'forexecution.16:58:31.523|INFO|Taskrun'email someone@gmail.com-0'-FinishedinstateCompleted()16:58:31.713|INFO|Flowrun'busy-bat'-FinishedinstateCompleted('All states completed.')Please note, many email services, like Gmail, require anApp Passwordto successfully send emails. If you encounter an error similar tosmtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted..., it's likely you are not using an App Password.Capture exceptions and notify by emailPerhaps you want an email notification with the details of the exception when your flow run fails.prefect-emailcan be wrapped in anexceptstatement to do just that!fromprefectimportflowfromprefect.contextimportget_run_contextfromprefect_emailimportEmailServerCredentials,email_send_messagedefnotify_exc_by_email(exc):context=get_run_context()flow_run_name=context.flow_run.nameemail_server_credentials=EmailServerCredentials.load("email-server-credentials")email_send_message(email_server_credentials=email_server_credentials,subject=f"Flow run{flow_run_name!r}failed",msg=f"Flow run{flow_run_name!r}failed due to{exc}.",email_to=email_server_credentials.username,)@flowdefexample_flow():try:1/0exceptExceptionasexc:notify_exc_by_email(exc)raiseexample_flow()ResourcesFor more tips on how to use tasks and flows in a Collection, check outUsing Collections!InstallationInstallprefect-emailwithpip:pipinstallprefect-emailThen, register toview the blockon Prefect Cloud:prefectblockregister-mprefect_emailNote, to use theloadmethod on Blocks, you must already have a block documentsaved through codeorsaved through the UI.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. For more information about how to use Prefect, please refer to thePrefect documentation.Saving credentials to blockNote, to use theloadmethod on Blocks, you must already have a block documentsaved through codeorsaved through the UI.Below is a walkthrough on saving block documents through code.Create a short script, replacing the placeholders.fromprefect_emailimportEmailServerCredentialscredentials=EmailServerCredentials(username="EMAIL-ADDRESS-PLACEHOLDER",password="PASSWORD-PLACEHOLDER",# must be an app password)credentials.save("BLOCK-NAME-PLACEHOLDER")Congrats! You can now easily load the saved block, which holds your credentials:fromprefect_emailimportEmailServerCredentialsEmailServerCredentials.load("BLOCK_NAME_PLACEHOLDER")!!! info "Registering blocks"Register blocks in this module to
[view and edit them](https://orion-docs.prefect.io/ui/blocks/)
on Prefect Cloud:

```bash
prefect block register -m prefect_email
```A list of available blocks inprefect-emailand their setup instructions can be foundhere.FeedbackIf you encounter any bugs while usingprefect-email, feel free to open an issue in theprefect-emailrepository.If you have any questions or issues while usingprefect-email, you can find help in either thePrefect Discourse forumor thePrefect Slack community.Feel free to star or watchprefect-emailfor updates too!ContributingIf you'd like to help contribute to fix an issue or add a feature toprefect-email, pleasepropose changes through a pull request from a fork of the repository.Here are the steps:Fork the repositoryClone the forked repositoryInstall the repository and its dependencies:pip install -e ".[dev]"Make desired changesAdd testsInsert an entry toCHANGELOG.mdInstallpre-committo perform quality checks prior to commit:pre-commit installgit commit,git push, and create a pull request