Files
tryton/trytond/doc/ref/sendmail.rst
T

56 lines
2.1 KiB
ReStructuredText
Raw Normal View History

2016-03-28 22:40:37 +02:00
.. _ref-sendmail:
.. module:: trytond.sendmail
Sendmail
========
.. function:: sendmail_transactional(from_addr, to_addrs, msg[, transaction[, datamanager[, strict]]])
2016-03-28 22:40:37 +02:00
2022-03-27 16:06:09 +02:00
Send email message only if the current transaction is successfully committed.
2016-03-28 22:40:37 +02:00
The required arguments are an :rfc:`5322` from-address string, a list of
:rfc:`5322` to-address strings (a bare string is treated as a list with 1
2022-03-27 16:06:09 +02:00
address), and an email message.
2022-04-06 18:19:49 +02:00
The caller may pass a :class:`~trytond.transaction.Transaction` instance to
join otherwise the current one is joined.
A specific data manager can be specified otherwise the default
:class:`SMTPDataManager` is used for sending email.
2022-03-27 16:06:09 +02:00
The strict value is passed to instantiate the default :class:`SMTPDataManager`.
2016-03-28 22:40:37 +02:00
2022-03-27 16:06:09 +02:00
.. warning::
An SMTP failure is only logged without raising any exception.
2016-03-28 22:40:37 +02:00
.. function:: sendmail(from_addr, to_addrs, msg[, server[, strict]])
2016-03-28 22:40:37 +02:00
2022-03-27 16:06:09 +02:00
Send email message like :meth:`sendmail_transactional` but directly without
2022-04-06 18:19:49 +02:00
caring about the transaction and return the ``server``.
2022-03-27 16:06:09 +02:00
The caller may pass a server instance from `smtplib`_.
It may return a new server instance if a reconnection was needed and if the
instance comes from :meth:`get_smtp_server`.
If strict is ``True``, an exception is raised if it is not possible to
connect to the server.
2016-03-28 22:40:37 +02:00
.. function:: get_smtp_server([uri[, strict]])
2016-03-28 22:40:37 +02:00
2022-03-27 16:06:09 +02:00
Return a SMTP instance from `smtplib`_ using the ``uri`` or the one defined
in the ``email`` section of the :ref:`configuration <topics-configuration>`.
If strict is ``True``, an exception is raised if it is not possible to
connect to the server.
2016-03-28 22:40:37 +02:00
2020-07-21 14:33:49 +02:00
.. class:: SMTPDataManager([uri[, strict]])
2016-03-28 22:40:37 +02:00
2022-03-27 16:06:09 +02:00
Implement a data manager which send queued email at commit.
An option optional ``uri`` can be passed to configure the SMTP connection.
If strict is ``True``, the data manager prevents the transaction if it fails
to send the emails.
2016-03-28 22:40:37 +02:00
.. method:: SMTPDataManager.put(from_addr, to_addrs, msg)
2022-03-27 16:06:09 +02:00
Queue the email message to send.
2016-03-28 22:40:37 +02:00
.. _`smtplib`: https://docs.python.org/2/library/smtplib.html