r/FastAPI • • Mar 07 '22

Question (HELP)Sending embed text mail within HTML mail using fastapi-mail

Hi, I need some help with email. I'm attempting to send an email through fastapi-mail (which works flawlessly). However, I also want to embed a plaintext version of the email in case certain devices dont support the HTML in my email. How do I go about doing this on FastAPI?

My current code :

async def send_email(email: list, instance: User):
    payload = {
        "email": instance.email,
    }


    message = MessageSchema(
        subject="Test mail",
        recipients=email,
        template_body={
            "test": "test"}
    )

    fm = FastMail(conf)
    await fm.send_message(message, template_name="email.html")

and the email.html file is a regular html file containing body and some <p> tags.

1 Upvotes

1 comment sorted by

2

u/sasmariozeld Mar 07 '22

i dont know why you would need fastapi mail... https://realpython.com/python-send-email/

python has everythig you need in the standard library