ppms.customizer.mail
This package lets you send emails from a Python context.
Functions
Reading mail related global settings
Function | Parameters | Return Value | Description |
---|---|---|---|
get_smtp_server_address() | String | Returns the value of the smtp server address global setting | |
get_smtp_server_port() | String | Returns the value of the smtp server port global setting | |
get_default_email_sender() | String | Returns the value of the default email sender global setting | |
get_smtp_username() | String | Returns the value of the smtp username global setting | |
get_smtp_password() | String | Returns the value of the smtp password global setting |
Reading mail related user data
Function | Parameters | Return Value | Description |
---|---|---|---|
get_user_email(user ) | user: user id from DI 010323 in 511 | String or None | Returns 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
Function | Parameters | Return Value | Description |
---|---|---|---|
get_default_message() | email.message.EmailMessage instance | Creates 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 instance | Creates 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 |
| Creates a html |
Classes
EmailContext
Methods
Function | Parameters | Return Value | Description |
---|---|---|---|
EmailContext.__init__(self, user=None, password=None ) | user: Optional user to use as authentication against the smtp server If 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 instance | Initialize a new EmailContext object for sending mails. |
EmailContext.__enter__(self ) | EmailContext instance | Connect 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 instance | returns the result of https://docs.python.org/3/library/smtplib.html#smtplib.SMTP.send_message | Send 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)
- Globale Einstellungen (Projekt) MOD009DJ5
- Global Settings (Project) MOD009DJ5
- Globale Einstellungen (Projekt) MOD009DJ5
- Global Settings (Project) MOD009DJ5
- Globale Einstellungen (Projekt) MOD009DJ5
- Global Settings (Project) MOD009DJ5
- Globale Einstellungen (Projekt) MOD009DJ5
- Global Settings (Project) MOD009DJ5
- Globale Einstellungen (Projekt) MOD009DJ5
- Global Settings (Project) MOD009DJ5
- Globale Einstellungen (Projekt) MOD009DJ5
- Global Settings (Project) MOD009DJ5