pipeline.src.helpers.emails

Functions

create_html_email(→ email.message.EmailMessage)

Creates a email.EmailMessage with the defined parameters.

create_sms_email(→ email.message.EmailMessage)

Creates a email.EmailMessage with the defined parameters, configured to be sent

create_fax_email(→ email.message.EmailMessage)

Creates a email.EmailMessage with the defined parameters.

send_email(→ dict)

Sends input email using the contents of From header as sender and To, Cc

send_sms(→ dict)

Same as send_email, using sms server.

send_fax(→ dict)

Same as send_email, using fax server.

send_email_or_sms_or_fax_message(→ dict)

resize_pdf_to_A4(→ bytes)

Module Contents

pipeline.src.helpers.emails.create_html_email(to: str | List[str], subject: str, html: str, from_: str = MONITORFISH_EMAIL_ADDRESS, cc: str | List[str] = None, bcc: str | List[str] = None, images: List[pathlib.Path] = None, attachments: List[Tuple[str, bytes]] = None, reply_to: str = None) email.message.EmailMessage[source]

Creates a email.EmailMessage with the defined parameters.

Parameters:
  • to (Union[str, List[str]]) – email address or list of email addresses of recipient(s)

  • subject (str) – Subject of the email.

  • html (str) – html representation of the email’s content.

  • from (str, optional) – From field. Defaults to env var MONITORFISH_EMAIL_ADDRESS.

  • cc (Union[str, List[str]], optional) – Cc field with optional email address

  • recipient ((or list of email addresses) of hidden copied)

  • bcc (Union[str, List[str]], optional) – Bcc field with optional email address

  • recipient

  • fromFrom field. Defaults to MONITORFISH_EMAIL_ADDRESS env var.

  • images (List[Path], optional) –

    List of Path to images on the server’s file system to attach to the email. These images can be displayed in the html body of the email by referencing them in the src attribute of an <img> tag as cid:<image_name>, where <image_name> is the image file’s name.

    For example: /a/b/c/my_image_123.png can be included in the html message as :

    <img src=”cid:my_image_123.png”> in the html message.

    Defaults to None.

  • attachments (List[Tuple[str, bytes]], optional) – list of attachments to add to the email. Elements of the list must be pairs of (filename, content). Defaults to None.

  • reply_to (str, optional) – if given, added as Reply-To header. Defaults to None.

Returns:

EmailMessage

pipeline.src.helpers.emails.create_sms_email(to: str | List[str], text: str, from_: str = MONITORFISH_EMAIL_ADDRESS) email.message.EmailMessage[source]

Creates a email.EmailMessage with the defined parameters, configured to be sent as an SMS.

Parameters:
  • to (Union[str, List[str]]) – phone number or list of phone numbers of recipient(s)

  • text (str) – text of the SMS message

  • from (str, optional) – From field. Defaults to MONITORFISH_EMAIL_ADDRESS env var.

Returns:

EmailMessage

pipeline.src.helpers.emails.create_fax_email(to: str | List[str], pdf: bytes, from_: str = MONITORFISH_EMAIL_ADDRESS) email.message.EmailMessage[source]

Creates a email.EmailMessage with the defined parameters.

Parameters:
  • to (Union[str, List[str]]) – email address or list of email addresses of recipient(s)

  • pdf (bytes) – bytes pdf object

  • from (str, optional) – From field. Defaults to MONITORFISH_EMAIL_ADDRESS env var.

Returns:

EmailMessage

pipeline.src.helpers.emails.send_email(msg: email.message.EmailMessage) dict[source]

Sends input email using the contents of From header as sender and To, Cc and Bcc headers as recipients.

This method will return normally if the mail is accepted for at least one recipient. It returns a dictionary, with one entry for each recipient that was refused. Each entry contains a tuple of the SMTP error code and the accompanying error message sent by the server, like :

{ “three@three.org” : ( 550 ,”User unknown” ) }

Parameters:

msg (EmailMessage) – email.message.EmailMessage to send.

Returns:

{email_address(error_code, error_message)} for all recipients that

were refused.

Return type:

dict

Raises:
  • SMTPHeloError – The server didn’t reply properly to the helo greeting.

  • SMTPRecipientsRefused – The server rejected ALL recipients (no mail was sent).

  • SMTPSenderRefused – The server didn’t accept the from_addr.

  • SMTPDataError – The server replied with an unexpected error code (other than a refusal of a recipient).

  • SMTPNotSupportedError – The mail_options parameter includes ‘SMTPUTF8’ but the SMTPUTF8 extension is not supported by the server.

  • ValueError – if there is more than one set of ‘Resent-’ headers

pipeline.src.helpers.emails.send_sms(msg: email.message.EmailMessage) dict[source]

Same as send_email, using sms server.

pipeline.src.helpers.emails.send_fax(msg: email.message.EmailMessage) dict[source]

Same as send_email, using fax server.

pipeline.src.helpers.emails.send_email_or_sms_or_fax_message(msg: email.message.EmailMessage, communication_means: src.entities.communication_means.CommunicationMeans, is_integration: bool, logger: logging.Logger) dict[source]
pipeline.src.helpers.emails.resize_pdf_to_A4(pdf: bytes) bytes[source]