prefect
prefect copied to clipboard
Fix authenticate bug and add unverified context
Description
This PR introduces a new configuration parameter "verify", which determines whether an unverified SSL context should be used. By default, this parameter is set to True.
Purpose
When using custom certificates for the email server, email functionality may fail due to certificate verification issues. To address this, the new "verify" parameter allows users to initialize an unverified SSL context, facilitating successful email transmission in such cases.
Bug Fix
Additionally, this PR fixes a bug related to the handling of insecure email servers, ensuring we will authenticate in the case of having username and password.
Related PRs and issues in prefect_email repository
PR 81 Issue 13089 PR 70 Issue 13091
Example
from prefect import flow
from prefect.context import get_run_context
from prefect_email import EmailServerCredentials, email_send_message
credentials = EmailServerCredentials(
username="EMAIL-ADDRESS-PLACEHOLDER",
password="PASSWORD-PLACEHOLDER",
smtp_type="STARTTLS",
verify=False
)
credentials.save("email-server-credentials")
def notify_exc_by_email(exc):
context = get_run_context()
flow_run_name = context.flow_run.name
email_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,
)
@flow
def example_flow():
try:
1 / 0
except Exception as exc:
notify_exc_by_email(exc)
raise
Checklist
- [x] This pull request references any related issue by including "closes
<link to issue>
" - [x] If this pull request adds new functionality, it includes unit tests that cover the changes
- [ ] This pull request includes a label categorizing the change e.g.
maintenance
,fix
,feature
,enhancement
,docs
.
For documentation changes:
- [ ] This pull request includes redirect settings in
netlify.toml
for files that are removed or renamed.
For new functions or classes in the Python SDK:
- [x] This pull request includes helpful docstrings.
- [ ] If a new Python file was added, this pull request contains a stub page in the Python SDK docs and an entry in
mkdocs.yml
navigation.