magpie.api.notifications ======================== .. py:module:: magpie.api.notifications Attributes ---------- .. autoapisummary:: magpie.api.notifications.SMTPServerConfiguration magpie.api.notifications.LOGGER magpie.api.notifications.TEMPLATE_DIR magpie.api.notifications.DEFAULT_TEMPLATE_MAPPING Functions --------- .. autoapisummary:: magpie.api.notifications.get_email_template magpie.api.notifications.get_smtp_server_configuration magpie.api.notifications.get_smtp_server_connection magpie.api.notifications.make_email_contents magpie.api.notifications.send_email Module Contents --------------- .. py:data:: SMTPServerConfiguration .. py:data:: LOGGER .. py:data:: TEMPLATE_DIR .. py:data:: DEFAULT_TEMPLATE_MAPPING .. py:function:: get_email_template(template_constant: magpie.typedefs.Str, container: Optional[magpie.typedefs.AnySettingsContainer] = None) -> mako.template.Template Retrieves the template file with email content matching the custom application setting or the corresponding default. Allowed values of :paramref:`template_constant` are: - :envvar:`MAGPIE_GROUP_TERMS_APPROVED_EMAIL_TEMPLATE` - :envvar:`MAGPIE_GROUP_TERMS_SUBMISSION_EMAIL_TEMPLATE` - :envvar:`MAGPIE_USER_REGISTRATION_SUBMISSION_EMAIL_TEMPLATE` - :envvar:`MAGPIE_USER_REGISTRATION_APPROVAL_EMAIL_TEMPLATE` - :envvar:`MAGPIE_USER_REGISTRATION_APPROVED_EMAIL_TEMPLATE` - :envvar:`MAGPIE_USER_REGISTRATION_DECLINED_EMAIL_TEMPLATE` - :envvar:`MAGPIE_USER_REGISTRATION_NOTIFY_EMAIL_TEMPLATE` :raises IOError: if an explicit override value of the requested template cannot be located. :returns: template formatter from the requested template file. .. py:function:: get_smtp_server_configuration(settings: magpie.typedefs.SettingsType) -> SMTPServerConfiguration Obtains and validates all required configuration parameters for SMTP server in order to send an email. .. py:function:: get_smtp_server_connection(config: SMTPServerConfiguration) -> Union[smtplib.SMTP, smtplib.SMTP_SSL] Obtains an opened connection to a SMTP server from application settings. If the connection is correctly instantiated, the returned SMTP server will be ready for sending emails. .. py:function:: make_email_contents(config: SMTPServerConfiguration, settings: magpie.typedefs.SettingsType, template: mako.template.Template, parameters: Optional[TemplateParameters] = None) -> magpie.typedefs.Str Generates the email contents using the template, substitution parameters, and the target email server configuration. .. py:function:: send_email(recipient: magpie.typedefs.Str, container: magpie.typedefs.AnySettingsContainer, template: mako.template.Template, parameters: Optional[TemplateParameters] = None) -> bool Send email notification using provided template and parameters. The preparation steps of the email (retrieve SMTP configuration, setup the SMTP connection, define email content parameters and attempt template generation) will directly raise if invalid as they correspond to incorrect application code or configuration settings. Following step to send the email with the established SMTP connection is caught and logged if raising an exception. This is to allow the calling operation to ignore failing email notification and act accordingly using the resulting email status. :param recipient: Email address of the intended recipient to which the email must be sent. :param template: Mako template used for the email contents. :param container: Any container to retrieve application settings. :param parameters: Parameters to provide for templating email contents. They are applied on top of various defaults values provided to all emails. :raises: any SMTP server configuration, template generator or parameter parsing error for email setup. :returns: success status of the notification email (sent without error, no guarantee of reception).