net.smtp
========

.. py:module:: net.smtp


Attributes
----------

.. autoapisummary::

   net.smtp.logger
   net.smtp.system_sendmail_fallback


Functions
---------

.. autoapisummary::

   net.smtp.sendmail
   net.smtp.send_message


Module Contents
---------------

.. py:data:: logger

.. py:data:: system_sendmail_fallback
   :value: False


.. py:function:: sendmail(from_email: str, to_emails: list[str], mail_as_string: str, smtp_servers: collections.abc.Sequence[str], max_size: int = 40, message_id: str | None = None) -> bool

   Send an email with stmplib.

   Fallback to /usr/lib/sendmail or /usr/sbin/sendmail if
   ``e3.net.smtp.system_sendmail_fallback`` is set to True (default False).

   :param from_email: the address sending this email (e.g. user@example.com)
   :param to_emails: A list of addresses to send this email to.
   :param mail_as_string: the message to send (with headers)
   :param smtp_servers: list of smtp server names (hostname), in case of
      exception on a server, the next server in the list will be tried
   :param max_size: do not send the email via smptlib if bigger than
       'max_size' Mo.
   :param message_id: the message id (for debugging purposes)

   :return: boolean (sent / not sent)

   We prefer running smtplib so we can manage the email size.
   We run sendmail in case it fails, assuming the max_size on the system
   is high enough - the advantage of sendmail is that it queues the
   email and retries a few times if the target server is unable
   to receive it.


.. py:function:: send_message(from_email: str, to_emails: list[str], subject: str, content: str, smtp_servers: list[str]) -> None

   Send an e-mail message.

   :param from_email: the address sending this email (e.g. user@example.com)
   :param to_emails: A list of addresses to send this email to
   :param subject: the e-mail's subject
   :param content: the e-mail's content


