core.email

Module Contents

Classes

EmailTransport

Helper class that provides a standard way to create an ABC using

EmailTransportSendInBlue

Helper class that provides a standard way to create an ABC using

Functions

cleanOldEmailsFromLog(*args, **kwargs)

Start the QueryIter DeleteOldEmailsFromLog to remove old, successfully send emails from the queue

sendEmailDeferred(emailKey: viur.core.db.KeyClass)

Callback from the Taskqueue to send the given Email

normalizeToList(value: Union[(None, Any, List[Any])]) → List[Any]

Convert the given value to a list.

sendEMail(*, tpl: str = None, stringTemplate: str = None, skel: Union[(None, Dict, 'SkeletonInstance', List['SkeletonInstance'])] = None, sender: str = None, dests: Union[(str, List[str])] = None, cc: Union[(str, List[str])] = None, bcc: Union[(str, List[str])] = None, headers: Dict[(str, str)] = None, attachments: List[Dict[str, Any]] = None, context: Union[(db.DATASTORE_BASE_TYPES, List[db.DATASTORE_BASE_TYPES], db.Entity)] = None, **kwargs) → Any

General purpose function for sending e-mail.

sendEMailToAdmins(subject: str, body: str, *args, **kwargs)

Sends an e-mail to the root users of the current app.

core.email.cleanOldEmailsFromLog(*args, **kwargs)

Start the QueryIter DeleteOldEmailsFromLog to remove old, successfully send emails from the queue

class core.email.EmailTransport

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

maxRetries = 3
abstract static deliverEmail(*, sender: str, dests: List[str], cc: List[str], bcc: List[str], subject: str, body: str, headers: Dict[str, str], attachments: List[Dict[str, bytes]], customData: Union[dict, None], **kwargs)

The actual email delivery must be implemented here. All email-adresses can be either in the form of “mm@example.com” or “Max Musterman <mm@example.com>”. If the delivery was successful, this method should return normally, if there was an error delivering the message it must raise an exception.

Parameters
  • sender – The sender to be used on the outgoing email

  • dests – List of recipients

  • cc – : List of carbon copy-recipients

  • bcc – List of blind carbon copy-recipients

  • subject – The subject of this email

  • body – The contents of this email (may be text/plain or text/html)

  • headers – Custom headers to send along with this email

  • attachments – List of attachments to include in this email

  • customData

static validateQueueEntity(entity: viur.core.db.Entity)

This function can be used to pre-validate the queue entity before it’s deferred into the queue. Must raise an exception if the email cannot be send (f.e. if it contains an invalid attachment) :param entity: The entity to validate

static transportSuccessfulCallback(entity: viur.core.db.Entity)

This callback can be overridden by the project to execute additional tasks after an email has been successfully send. :param entity: The entity which has been send

core.email.sendEmailDeferred(emailKey: viur.core.db.KeyClass)

Callback from the Taskqueue to send the given Email :param emailKey: Database-Key of the email we should send

core.email.normalizeToList(value: Union[None, Any, List[Any]])List[Any]

Convert the given value to a list.

core.email.sendEMail(*, tpl: str = None, stringTemplate: str = None, skel: Union[None, Dict, SkeletonInstance, List[SkeletonInstance]] = None, sender: str = None, dests: Union[str, List[str]] = None, cc: Union[str, List[str]] = None, bcc: Union[str, List[str]] = None, headers: Dict[str, str] = None, attachments: List[Dict[str, Any]] = None, context: Union[db.DATASTORE_BASE_TYPES, List[db.DATASTORE_BASE_TYPES], db.Entity] = None, **kwargs)Any

General purpose function for sending e-mail. This function allows for sending e-mails, also with generated content using the Jinja2 template engine. Your have to implement a method which should be called to send the prepared email finally. For this you have to allocate viur.email.transportClass in conf.

Parameters
  • tpl – The name of a template from the deploy/emails directory.

  • stringTemplate – This string is interpreted as the template contents. Alternative to load from template file. :param skel: The data made available to the template. In case of a Skeleton or SkelList, its parsed the usual way; Dictionaries are passed unchanged.

  • sender – The address sending this mail.

  • dests – A list of addresses to send this mail to. A bare string will be treated as a list with 1 address.

  • cc – Carbon-copy recipients. A bare string will be treated as a list with 1 address.

  • bcc – Blind carbon-copy recipients. A bare string will be treated as a list with 1 address.

  • headers – Specify headers for this email.

  • attachments

    List of files to be sent within the mail as attachments. Each attachment must be a dictionary with these keys:

    filename (string): Name of the file that’s attached. Always required content (bytes): Content of the attachment as bytes. Required for the send in blue API. mimetype (string): Mimetype of the file. Suggested parameter for other implementations (not used by SIB) gcsfile (string): Link to a GCS-File to include instead of content. Not supported by the current

    SIB implementation

  • context – Arbitrary data that can be stored along the queue entry to be evaluated in transportSuccessfulCallback (useful for tracking delivery / opening events etc).

core.email.sendEMailToAdmins(subject: str, body: str, *args, **kwargs)

Sends an e-mail to the root users of the current app.

Parameters
  • subject – Defines the subject of the message.

  • body – Defines the message body.

class core.email.EmailTransportSendInBlue

Bases: core.email.EmailTransport

Helper class that provides a standard way to create an ABC using inheritance.

maxRetries = 3
allowedExtensions
static splitAddress(address: str)Dict[str, str]

Splits an Name/Address Pair as “Max Musterman <mm@example.com>” into a dict {“name”: “Max Mustermann”, “email”: “mm@example.com”} :param address: Name/Address pair :return: Splitted dict

static deliverEmail(*, sender: str, dests: List[str], cc: List[str], bcc: List[str], subject: str, body: str, headers: Dict[str, str], attachments: List[Dict[str, bytes]], **kwargs)

Internal function for delivering Emails using Send in Blue. This function requires the conf[“viur.email.sendInBlue.apiKey”] to be set. This function is supposed to return on success and throw an exception otherwise. If no exception is thrown, the email is considered send and will not be retried.

static validateQueueEntity(entity: viur.core.db.Entity)

For Send in Blue, we’ll validate the attachments (if any) against the list of supported file extensions