kerno.email package¶
Module contents¶
Extensible scheme for an app to send out email messages.
We provide only a well-structured API to build messages, such that classes representing individual email messages are easy to change and easy to test. And any backend capable of actually sending out emails can be plugged at the end.
- class kerno.email.EmailAddress(email: kerno.typing.TEmailAddress, name: kerno.typing.TPersonsName = '')[source]¶
Bases:
object
Represents an email address, optionally with the person’s name.
- email: kerno.typing.TEmailAddress¶
- email_validator = <bag.email_validator.EmailValidator object>¶
- name: kerno.typing.TPersonsName¶
- class kerno.email.EmailMessageBase(adict: Dict[str, Any], envelope: kerno.email.Envelope)[source]¶
Bases:
object
Abstract base class to build an email message from templates.
The plain text version is automatically built from the HTML version.
Subclasses should declare certain static variables:
class ACertainEmailMessage(EmailMessageBase): SUBJECT = 'Life or death matter in {app_name}!!!1' HTML_TEMPLATE = 'path/to/template.jinja2'
- html¶
Must be overridden in subclasses to return the HTML version.
Usually based on HTML_TEMPLATE. Example implementation:
@reify def rich(self): return jinja2.get_template( self.HTML_TEMPLATE).render(self.adict)
- plain¶
Autogenerate the plain text version from the rich version.
- subject¶
May be overridden in subclasses to decorate the subject line.
- class kerno.email.Envelope(recipients: List[kerno.email.EmailAddress], cc: Optional[List[kerno.email.EmailAddress]] = None, bcc: Optional[List[kerno.email.EmailAddress]] = None, reply_to: Optional[kerno.email.EmailAddress] = None, sender: Optional[kerno.email.EmailAddress] = None)[source]¶
Bases:
object
Represents the envelope of an email message.