This package lets you send emails from a Python context.

Functions

Reading mail related global settings

FunctionParametersReturn ValueDescription
get_smtp_server_address()
StringReturns the value of the smtp server address global setting
get_smtp_server_port()
StringReturns  the value of the smtp server port global setting
get_default_email_sender()
StringReturns the value of the default email sender global setting
get_smtp_username()
StringReturns the value of the smtp username global setting
get_smtp_password()
StringReturns the value of the smtp password global setting

Reading mail related user data

FunctionParametersReturn ValueDescription
get_user_email(user)user: user id from DI 010323 in 511String or NoneReturns the value of the users email address or None if the user does not exist

Creating a new message object

See the Python docs for documentation on the EmailMessage class: https://docs.python.org/3/library/email.message.html

FunctionParametersReturn ValueDescription
get_default_message()
email.message.EmailMessage instanceCreates a default EmailMessage object with the sender read from the global setting
get_default_text_message(recipient, subject, content)

recipient: string containing the email address of the recipient. If you have multiple recipients you can use a string containing a comma separated list of addresses.

subject: string subject of the email.

content: string The text body of the email

email.message.EmailMessage instanceCreates a default EmailMessage object with sender, recipient, subject and content set.
get_default_html_message(recipient, subject, content)

recipient: string containing the email address of the recipient. If you have multiple recipients you can use a string containing a comma separated list of addresses.

subject: string subject of the email.

content: string The html body of the email

email.mime.text.MIMEText instance

Creates a html MIMEText object with sender, recipient, subject and content set.


Classes

EmailContext

Methods

FunctionParametersReturn ValueDescription
EmailContext.__init__(self, user=None, password=None)

user: Optional user to use as authentication against the smtp server If None is used the smtp username global setting is read and used.

password: Optional password to use as authentication against the smtp server. If None is used the smtp username global setting is read and used.

EmailContext instanceInitialize a new EmailContext object for sending mails.
EmailContext.__enter__(self)
EmailContext instanceConnect to the SMTP server and optionally authenticate with the server if the parameters were set.
EmailContext.__exit__(self, exc_type, exc_val, exc_tb)

exc_type: Exception type.

exc_val: Exception value.

exc_tb: Exception traceback


Disconnect from the SMTP server
EmailContext.send_message(self, message)message: email.message.EmailMessage or child instancereturns the result of https://docs.python.org/3/library/smtplib.html#smtplib.SMTP.send_messageSend a EmailMessage object

Example Code

Sending a mail to multiple recipients using the EmailContext context manager

from ppms.customizer import mail

recipient_list = ['customizer1@example.com', 'customizer2@example.com']
recipient = ','.join(recipient_list)

subject = 'E-Mail Sending Example'
content = 'Hello World!'

message = mail.get_default_text_message(recipient=recipient, subject=subject, content=content)

with mail.EmailContext() as m:
    response = m.send_message(message=message)
PY