core.mail
Attributes
Classes
Represents a mail attachment that can be passed to prepare_email |
Functions
|
|
|
Applies Quoted Printable encoding to the display name according |
|
Coerces a string type into a email.headerregistry.Address object |
|
Formats a single Address according to Postmark API rules that is |
|
Convenience function that accepts both a single Address and a |
|
Creates a dictiornary that can be turned into JSON as is and sent |
Module Contents
- core.mail.qp_encode_display_name(display_name: str) str [source]
Applies Quoted Printable encoding to the display name according to Postmark API’s rules that can be parsed losslessly back into the original display_name with the EmailMessage API.
- core.mail.coerce_address(address: email.headerregistry.Address | str) email.headerregistry.Address [source]
Coerces a string type into a email.headerregistry.Address object by parsing the string as a sender header.
It acts like parseaddr for string values, but undoes QP-encoding for the display_name which parseaddr does not.
- NOTE: This function should probably go away, once we switch to
using Address objects everywhere. Or we make it more strict by asserting that string values need to be an email address without display_name, so we can use Address(addr_spec=address) to coerce it, which should be faster than header_factory.
- core.mail.format_single_address(address: email.headerregistry.Address | str) str [source]
Formats a single Address according to Postmark API rules that is cross-compatible with email.message.EmailMessage for raw SMTP sends.
The rules state that backslash escaping quotes is illegal and quoted printable encoded display names need to be split into space-separated encoded words of maximum length 75, with the entire display name enclosed in double quotes if it contains more than one word.
- Parameters:
address – email.headerregistry.Address or preformatted string
- core.mail.format_address(addresses: SequenceOrScalar[Address | str]) str [source]
Convenience function that accepts both a single Address and a sequence of Address, otherwise identical to format_single_address
It enforces a limit of 50 addresses, due to Postmark API restrictions
- Parameters:
addresses – Single Address/str or sequence thereof
- class core.mail.Attachment(filename: _typeshed.StrPath, content: SupportsRead[str | bytes] | str | bytes | None = None, content_type: str | None = None)[source]
Represents a mail attachment that can be passed to prepare_email
- core.mail.prepare_email(sender: email.headerregistry.Address | str, reply_to: email.headerregistry.Address | str | None = None, receivers: SequenceOrScalar[Address | str] = (), cc: SequenceOrScalar[Address | str] = (), bcc: SequenceOrScalar[Address | str] = (), subject: str | None = None, content: str | None = None, plaintext: str | None = None, attachments: Iterable[Attachment | StrPath] = (), headers: dict[str, str] | None = None, stream: str = 'marketing') core.types.EmailJsonDict [source]
Creates a dictiornary that can be turned into JSON as is and sent to the Postmark API.
- Parameters:
content – HTML content.
attachments – Either a list of
onegov.core.email.Attachment
or a list of filenames/os.PathLike to attach to the email.headers – Dictionary containing additional headers to be set