Hi Folks, Is there an example of sending emails us...
# ask-community
s
Hi Folks, Is there an example of sending emails using Sendgrid using prefect? I can send emails via sendgrid API without issues. However, while using it with prefect I am getting a
ForbiddenError: HTTP Error 403: Forbidden
m
Hello Shyam! I don't see any significant changes on Sendgrid side, would you mind to post a minimal example of your setup (using a Prefect task, redacting Sendgrid api key)?
This is my simple working example. I installed prefect with sendgrid extra (
pip install "prefect[sendgrid]"
), generated a sendgrid api key and ran this flow
Copy code
from prefect import Flow
from prefect.tasks.sendgrid import SendEmail

sengrid_send_email = SendEmail(
    from_email="<mailto:notifications@prefect.io|notifications@prefect.io>",
    to_emails="<your@email>",
    subject="Test Prefect Sendgrid Task",
    html_content="<strong>and easy to do anywhere, even with Python</strong>",
    sendgrid_api_key="<>"
)

with Flow("Sendgrid Flow") as flow:
    sengrid_send_email()

flow.register(project_name="Examples")
s
@Mariia Kerimova Thanks it worked. One more question, is it possible to do bcc for to_email? It seems that the parameter is not there. I see some option with Sendgrid. https://code.luasoftware.com/tutorials/sendgrid/python-sendgrid-bcc/
m
Looks like it's not possible right now. But we always welcome contributors to Prefect tasks library, and adding bcc can be easily achieved, by adding Sendgrid bcc here.
s
Sure. Thank you.
👍 1
348 Views