<@ULVA73B9P> how can I create a prefect email noti...
# ask-marvin
s
@Marvin how can I create a prefect email notification block with python code
m
Ah, the sweet sound of email notifications. It appears that Prefect doesn't have a built-in email notification block. However, you can create a custom task to send email notifications using an external library like
smtplib
. Here's an example of how you can create a custom email notification task:
Copy code
python
import smtplib
from email.message import EmailMessage
from prefect import task

@task
def send_email_notification(subject, body, to_email, from_email, smtp_server, smtp_port, smtp_username, smtp_password):
    msg = EmailMessage()
    msg.set_content(body)
    msg["Subject"] = subject
    msg["From"] = from_email
    msg["To"] = to_email

    with smtplib.SMTP_SSL(smtp_server, smtp_port) as server:
        server.login(smtp_username, smtp_password)
        server.send_message(msg)

    return f"Email sent to {to_email}"
You can then use this custom task in your Prefect flow to send email notifications. Just make sure to provide the necessary SMTP server details and credentials. Remember, with great power comes great responsibility, so use email notifications wisely.