EmailPublisher

class qf_lib.documents_utils.email_publishing.email_publisher.EmailPublisher(settings: qf_lib.settings.Settings)[source]

Bases: object

Used to create and send an e-mail from given templates.

Methods

publish(mail_to, List[str]], subject, …)

Creates and sends an e-mail from given templates.

publish(mail_to: Union[str, List[str]], subject: str, template_path: str, cc: Union[str, List[str]] = None, bcc: Union[str, List[str]] = None, attachments: List[str] = (), context: Dict[str, object] = None, templates_encoding: str = 'utf8')[source]

Creates and sends an e-mail from given templates. It’s possible to add some attachments to the message. Subject, e-mail addresses (to, cc, bcc) and message template may contain so called “placeholders” like {{ username }} (they need to be placed in the double curly brackets). Later it’s necessary to pass the context parameter from which data will be taken to substitute placeholders

Parameters
  • mail_to – single e-mail address or the list/tuple of them. It denotes the primary recipients of an e-mail

  • subject – subject of the message

  • template_path – path (relative to the email_templates_directory set in the settings file) to the template from which e-mail should be created

  • cc – the e-mail address (or list of them) of all the CC recipients

  • bcc – the e-mail address (or list of them) of all the CC recipients

  • attachments – a list of paths to the files which should be attached to an e-mail

  • context – dictionary with keys of type string. Keys’ names should correspond to the names of placeholders in the template

  • templates_encoding – the encoding of the template. The default one is UTF-8