Powered by Tachyonic Project Luxon Framework v0.0.0

Luxon Framework for rapid application development. (luxon)

Version

Email Utilities

SMTP Client

class luxon.utils.mail.SMTPClient(email, server, port=587, tls=False, auth=None)[source]

Utility Class for sending email via SMTP server.

Example usage:

with SMTPClient(email, server) as server:
    result = server.send(rcpt, subject=subject, body=body, msg=msg)
Parameters:
  • email (str) – Sender email address.
  • server (str) – IP address of SMTP server.
  • port (int) – TCP port of SMTP server.
  • tls (bool) – Whether or not to use TLS.
  • auth (tuple) – (username, password) to use for authentication.
smtp

object of class smtplib.SMTP.

Type:obj
email

Sender email address.

Type:str
send(email=None, subject=None, body=None, msg=None)[source]

Method to send Email.

Parameters:
  • email (str) – Recipient Email address.
  • subject (str) – Email Subject.
  • body (str) – Email Body
  • msg (obj) – object of python email library’s EmailMessage class.

Returns: Bool: True if sending was successful, else False.

Parse Content

class luxon.utils.mail.ParseContent(msg, html_template=None, text_template=None)[source]

Utility Class to Parse the content of a MIME message.

Parameters:
  • msg (obj) – object of python email library’s EmailMessage class.
  • html_template (str) – Name of jinja2 template to use to render HTML.
  • text_template (str) – Name of jinja2 template to use to render text.
attachments

Returns list of file attachment objects

html(**kwargs)[source]

Returns text as rendered by the html jinja2 template.

If no html was found, None is returned.

text(**kwargs)[source]

Returns text as rendered by the text jinja2 template.

If no text is found, the HTML rendered from the HTML template is returned, if both html and html template were present.

Parse Attachment

luxon.utils.mail.parse_attachment(message_part)[source]

Function to parse attachment from MIME message part.

Parameters:message_part (obj) – part in the MIME message object tree.
Returns:obj of either StringIO (for strings) else BytesIO. If no attachments were present, ‘None’ is returned.

New Message

luxon.utils.mail.new_message(subject=None, email_from=None, email_to=None, old_msg=None, multipart=True)[source]

Utility function to generate an email message.

Either generating a new message form scratch, or updates a previous message.

Parameters:
  • subject (str) – Email Subject.
  • email_from (str) – Sender email address.
  • email_to (str) – Recipient email address.
  • old_msg (obj) – object of python email library’s EmailMessage class to be updated.
  • multipart (bool) – Whether or not to create MIMEMultipart msg.
Returns:

obj of type MIMEMultipart if multipart is True, else EmailMessage.

Format Message

luxon.utils.mail.format_msg(msg, html_template=None, text_template=None, subject=None, email_from=None, email_to=None, multipart=None, attachments=True, **kwargs)[source]

Utility function to generate an email message with content rendered from jinja2 templates.

If multipart is not specified, a multipart message is returned.

Parameters:
  • msg (obj) – object of python email library’s EmailMessage class.
  • html_template (str) – Name of jinja2 template to use to render HTML.
  • text_template (str) – Name of jinja2 template to use to render text.
  • subject (str) – Email Subject.
  • email_from (str) – Sender email address.
  • email_to (str) – Recipient email address.
  • multipart (bool) – Whether or not to create MIMEMultipart msg.
  • attachments (bool) – Whether or not to include attachments.
  • kwargs (kwargs) – Keyword Args used to render the templates.
Returns:

Python email message object.