Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authenticate bug and add unverified context #13428

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sm-ghavami
Copy link

@sm-ghavami sm-ghavami commented May 17, 2024

Description

This PR introduces a new configuration parameter unverified_context, which determines whether an unverified SSL context should be used. By default, this parameter is set to False.

Purpose

When using custom certificates for the email server, prefect email functionality may fail due to certificate verification issues. To address this, the new unverified_context parameter allows users to initialize an unverified SSL context in such cases, facilitating successful email transmission.

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",
    unverified_context=True
)
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

  • This pull request references any related issue by including "closes <link to issue>"
  • 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:

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support of unverified smtp server Add authentication to INSECURE server
1 participant