Skip to content

feat: improve API for sending html and plain emails #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

whitehat101
Copy link

I'd like to send multipart emails with text and html using Jinja templates. This isn't well documented, but I found this PR #179 that enables basic features:

It ends up looking something like this:

message = MessageSchema(
    subject="Fastapi-Mail module",
    recipients=["[email protected]"],
    template_body={"name": "John Smith"},
    subtype=MessageType.html,
    alternative_body="This is a test email, but not from a template.",
    multipart_subtype=MultipartSubtypeEnum.alternative,
)
await Mailer.send_message(message, template_name="email.html.jinja")

I'd like to use Jinja templates for both. This PR allows it with a cleaner syntax.

message = MessageSchema(
    subject="Fastapi-Mail module",
    recipients=["[email protected]"],
    template_body={"name": "John Smith"},
    subtype=MessageType.html
)
await Mailer.send_message(message, html_template="email.html.jinja", plain_template="email.txt.jinja")

Where the template_body is passed into both versions of the template. It would be nice to have subtype become optional, but I don't want to make potentially breaking changes to the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant