feat: add FastMail.get_message() to return the prepared message without sending#322
Open
tungyhardDevOps wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #234
Motivation
#234 asks for a way to sign outgoing mail (e.g. S/MIME) — or, as the issue itself suggests, simply to "get the prepared message" so it can be signed and sent externally. Today the fully-built
email.message.Messageis only created inside the private send pipeline, so there is no supported way to obtain it without sending.Change
Adds a public async method
FastMail.get_message(...)that runs the same preparation pipeline assend_message(template rendering, sender resolution, MIME construction) but returns the preparedemail.message.Messageinstead of delivering it. It reuses the existing internal__prepare_messages_for_sending, so behaviour stays identical tosend_message.send_message(message,template_name,html_template,plain_template).MessageSchemareturns one message; a list returns a list.This unblocks the S/MIME / DKIM signing use case without fastapi-mail taking on a cryptography dependency — callers sign/post-process the returned message and send it via their own transport.
Tests
tests/test_get_message.py(3 tests, all passing):Messagewith correct headers/body, and asserts nothing is dispatched (record_messagesoutbox stays empty);Existing suite still green (
tests/test_connection.py: 22 passed).black,isort,flake8clean;mypyclean onfastmail.py.Docs
Documented the new method in
docs/getting-started.md.