<@ULVA73B9P> I'm looking into using `prefect-email...
# ask-marvin
m
@Marvin I'm looking into using
prefect-email
to send out notifications during flow runs. According to documentation, I need to create a EmailServerCredentials block, but when creating it there seems to be only option to send email through SMTP. Is it possible to send email through Outlook 365?
m
To send emails through Outlook 365 using the
prefect-email
library, you would still configure it via SMTP as Prefect does not have a specific integration for Outlook 365 but relies on generic SMTP configurations. Here's a way to set it up, and yes, this involves using the SMTP server details for Outlook 365: 1. SMTP Server Details for Outlook 365: - SMTP Server:
<http://smtp.office365.com|smtp.office365.com>
- SMTP Port:
587
- SMTP Encryption:
STARTTLS
- You will also need your Outlook email address and password (or app-specific password if 2FA is enabled). 2. Creating the
EmailServerCredentials
Block:
You would create a block in
prefect-email
like this:
Copy code
python
   from prefect_email import EmailServerCredentials

   credentials = EmailServerCredentials(
       smtp_server="<http://smtp.office365.com|smtp.office365.com>",
       smtp_port=587,
       smtp_type="STARTTLS",
       username="<mailto:your-email@outlook.com|your-email@outlook.com>",
       password="your-email-password"
   )
   credentials.save("your-block-name")
3. Note: Handling passwords directly in code is generally not advisable unless using secure management like environment variables or Prefect's secret management. If you're using App Passwords for Outlook, make sure they’re properly integrated. For detailed insights, you can check out the Prefect Email integration documentation for Prefect 2.x or Prefect 3.x. Self-awareness stopped me from diving into full existential musings, but trust me, configuring email notifications can occasionally feel like contemplating the vastness of the universe!
m
@Marvin Where did you get the SMTP server details for outlook 365? Is it documented anywhere?
m
The SMTP server details for Outlook 365, like
<http://smtp.office365.com|smtp.office365.com>
with port
587
and
STARTTLS
encryption, are standard configuration settings often referenced across various email client and mailing library documentation. Microsoft provides these settings for Outlook and Office 365 accounts. While these specific details weren't part of the Prefect documentation, they are generally documented and available from Microsoft’s documentation or support for setting up email clients like Outlook. For more detailed and authoritative instructions, you might want to check Microsoft's documentation directly or their support pages for Office 365 setup. If I could search Microsoft documentation for you, I would—alas, my digital reach doesn't extend that far just yet!
m
@Marvin There is no
<http://smtp.office365.com|smtp.office365.com>
option for SMTP server when creating the block. There is
<http://smtp-mail.outlook.com|smtp-mail.outlook.com>
. Should I be using this?
m
Ah, the joys of email server configurations! Yes, you can use
<http://smtp-mail.outlook.com|smtp-mail.outlook.com>
as the SMTP server when setting up your
EmailServerCredentials
block in Prefect. This is another valid endpoint for sending emails through Outlook and Office 365, especially for consumer Outlook accounts. Here's how you would configure it: 1. SMTP Server Details: - SMTP Server:
<http://smtp-mail.outlook.com|smtp-mail.outlook.com>
- SMTP Port:
587
- SMTP Encryption:
STARTTLS
2. Creating the Block: You'd set it up just like this:
Copy code
python
   from prefect_email import EmailServerCredentials

   credentials = EmailServerCredentials(
       smtp_server="<http://smtp-mail.outlook.com|smtp-mail.outlook.com>",
       smtp_port=587,
       smtp_type="STARTTLS",
       username="<mailto:your-email@outlook.com|your-email@outlook.com>",
       password="your-email-password"
   )
   credentials.save("your-block-name")
This configuration should enable you to send emails through your Outlook account. Just ensure you have the right credentials and possibly an App Password if you have two-factor authentication enabled. Remember, when dealing with email servers, trying out the configuration in a test flow first can be a good idea—no one wants to be stuck in email configuration limbo!
m
@Kevin Grismore Could you please confirm office365 will work with prefect-email? I'm having an authentication issue using configuration Marvin suggested