Can anyone help with email notification? From inst...
# prefect-getting-started
r
Can anyone help with email notification? From instructions it says Save your email credentials to a block: In order to send emails, you need to save your email credentials to a block. Here's how you can do it:
Copy code
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("your-block-name")
and then on flow
Copy code
# Load the email server credentials
    email_credentials_block = EmailServerCredentials.load("your-block-name")

    # Send an email
    email_send_message(
        email_server_credentials=email_credentials_block,
        subject="Flow Notification",
        msg="Flow run completed",
        email_to=my_email,
    )
Since I am on ec2, I need to push to my github so it will contain my gmail. How can I not expose it? I have not understood how it works apparently. Edit: I figured it out! I used
Copy code
from dotenv import load_dotenv
import os

load_dotenv()
my_email = os.getenv("MY_EMAIL")
and then
Copy code
export MY_EMAIL=email_you_want
without pushing the credentials block to github. Is this the way or is there another one?