seto
09/20/2024, 4:16 PMMarvin
09/20/2024, 4:17 PMprefect-email
package.
pip install -U prefect-email
2. Register Email Block Types:
Register the necessary block types to make them available for use.
python
prefect block register -m prefect_email
3. Save Email Server Credentials:
Save your email credentials (e.g., Gmail) to a block.
python
from prefect_email import EmailServerCredentials
credentials = EmailServerCredentials(
username="<mailto:your-email@example.com|your-email@example.com>",
password="your-app-password", # Must be an app password
)
credentials.save("email-server-credentials")
4. Send Emails Using a Flow:
Use the credentials block to send emails.
python
from prefect import flow
from prefect_email import EmailServerCredentials, email_send_message
@flow
def example_email_send_message_flow(email_addresses):
email_server_credentials = EmailServerCredentials.load("email-server-credentials")
email_send_message(
email_server_credentials=email_server_credentials,
subject="Test Email",
msg="This is a test email from Prefect",
email_to=email_addresses,
)
example_email_send_message_flow(["<mailto:recipient@example.com|recipient@example.com>"])
### Common Issues and Troubleshooting
- ModuleNotFoundError: No module named email.utils
:
This error usually indicates a misconfiguration or conflict with packages. Ensure there is no file named email.py
in your project directory, as it can shadow the built-in email module.
- SMTP Authentication Errors:
If you encounter authentication errors, ensure you are using an application-specific password, especially for Gmail.
### Useful Links
- Prefect Email Integration Docs (3.x)
- GitHub Issue related to `ModuleNotFoundError`: No module named 'email.utils'
Please follow these steps and double-check your environment setup. If the problem persists, please let me know, and we can dive deeper into specific issues.Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by