sabuhish / fastapi-mail

Fastapi mail system sending mails(individual, bulk) attachments(individual, bulk)
https://sabuhish.github.io/fastapi-mail/
MIT License
680 stars 82 forks source link

HTML Body rendering issue #141

Closed jzr-supove closed 2 years ago

jzr-supove commented 2 years ago

I'm sending html body, but its rendering incorrectly:

first html as plain text and rendered version underneath it

Code:

with open('template.html', mode='r', encoding='utf_8') as file:
    template = file.read()

message = MessageSchema(
    subject="Subject",
    recipients=[EmailStr(user.email)],
    body=template.format(name=user.full_name, code=code),
    subtype='html'
)

background_tasks.add_task(fast_mail.send_message, message)

Result:

alt text

jzr-supove commented 2 years ago

Hello?

jzr-supove commented 2 years ago

✅ Solved the issue by passing the html content to the html parameter of the MessageSchema instead of the body:

MessageSchema(
    subject="Subject",
    recipients=["example@mail.com"],
    html=html_template,   # <------
    subtype="html"
)

Example in the README.md documentation should be updated!