libs package

Submodules

libs.emailer module

This module contains the logic for sending emails with the python email module.

libs.emailer.logger

The logger used to log information of module.

Type

logging.Logger

class libs.emailer.Email[source]

Bases: object

Class used for sending multipart emails (text and html).

This class can send emails by combining a text version and an HTML version of an email separately, then merge them with the MIMEMultipart(‘alternative’) instance. This is such that the email has two rendering options, such that in case HTML can’t be rendered successfully, the text version can still be rendered.

_ENCRYPTION

The encryption type string.

Type

str

_PORT

The port number corresponding to the encryption type.

Type

int

_SMTP_SERVER

The SMTP server of the sender email.

Type

str

_FROM_EMAIL

The sender email.

Type

str

_FROM_PASSWORD

The sender’ email password.

Type

str

FROM_TITLE

The display name portion of the address.

Type

str

FROM_TITLE: str = 'Pricing Service'
classmethod send_mail(email: List[str], subject: str, text: str, html: str)[source]

Sends the email.

Parameters
  • email (List[str]) – The list of email addresses to send the email to.

  • subject (str) – The subject of the email message.

  • text (str) – The text version of the email message body.

  • html (str) – The HTML version of the email message body.

Raises

EmailException – If there was an error sending the email.

exception libs.emailer.EmailException(message: str)[source]

Bases: Exception

Class that is thrown when there is a Email error.

Parameters

message (str) – Human readable string describing the exception.

message

Human readable string describing the exception.

Type

str

class libs.emailer.Encryption(value)[source]

Bases: enum.Enum

Enumerate email encryption types.

Specifies the types of email encryption available.

SSL

SSl encryption string.

Type

str

TLS

TLS encryption string.

Type

str

SSL: str = 'ssl'
TLS: str = 'tls'
class libs.emailer.Port(value)[source]

Bases: enum.IntEnum

Enumerate port integer numbers for email encryption types.

SSL

Port number corresponding to SSL encryption.

Type

int

TLS

Port number corresponding to TLS encryption.

Type

int

SSL: int = 465
TLS: int = 587

libs.mailgun module

This module contains the logic for sending emails with Mailgun.

class libs.mailgun.Mailgun[source]

Bases: object

Class that handles the logic of sending emails by using the Mailgun API.

MAILGUN_API_KEY

The Mailgun API key.

Type

str

MAILGUN_API_KEY

The Mailgun API domain.

Type

str

FROM_TITLE

The sender name shown in the email.

Type

str

FROM_EMAIL

The sender email.

Type

str

FROM_EMAIL = 'do-not-reply@MAILGUN_DOMAIN'
FROM_TITLE = 'Pricing service'
MAILGUN_API_KEY = 'MAILGUN_API_KEY'
MAILGUN_DOMAIN = 'MAILGUN_DOMAIN'
classmethod send_mail(email: List[str], subject: str, text: str, html: str) → requests.models.Response[source]

Sends an email.

Parameters
  • email (List[str]) – The list containing the emails of the recipients.

  • subject (str) – The subject of the email message.

  • text (str) – The text equivalent of the email message body.

  • html (str) – The html equivalent of the email message body.

Returns

The response from the Mailgun API.

Return type

Response

Raises

MailgunException – If either the Mailgun API key or Mailgun domain failed to load. It will also be thrown if a bad API response was received from the post request.

exception libs.mailgun.MailgunException(message: str)[source]

Bases: Exception

Class that is thrown when there is a Mailgun error.

Parameters

message (str) – Human readable string describing the exception.

message

Human readable string describing the exception.

Type

str

Module contents