easymacro/docs/source/email.rst

110 lines
2.4 KiB
ReStructuredText

Email
=====
Remember, always import library.
.. code-block:: python
import easymacro as app
**IMPORTANT:** Always save your config the more security way possible.
Send email
----------
.. code-block:: python
from conf import PASSWORD
SERVER = dict(
server = 'mail.server.net' ,
port = 495,
ssl = True,
user = 'no-responder@noexiste.mx',
password = PASSWORD,
)
body = "Hello Ingrid\n\nWho are you?\n\nBest regards"
message = dict(
to = 'ingrid.bergman@love.you',
subject = 'I love you',
body = body,
)
app.email.send(SERVER, message)
* We can use fields `cc`, `bcc` too and send to more than one address emails.
.. code-block:: python
to = 'mail1@correo.com,mail2@correo.com,mail3@correo.com'
cc = 'other@correo.com'
bcc = 'hidden@correo.com'
* We can send too more than one message.
.. code-block:: python
message1 = dict(
to = 'ingrid.bergman@email.net',
subject = 'I love you',
body = "Hello Ingrid\n\nWho are you?\n\nBest regards",
)
message2 = dict(
to = 'sophia.loren@email.net',
subject = 'I love you',
body = "Hello Sophia\n\nWho are you?\n\nBest regards",
)
messages = (message1, message2)
app.email.send(SERVER, messages)
.. code-block:: bash
30/06/2021 13:43:23 - DEBUG - Connect to: mail.gandi.net
30/06/2021 13:43:24 - DEBUG - Email sent...
30/06/2021 13:43:26 - DEBUG - Email sent...
30/06/2021 13:43:26 - DEBUG - Close connection...
* Send with attachment
.. code-block:: python
files = '/home/mau/file.epub'
message = dict(
to = 'ingrid.bergman@email.net',
subject = 'I love you',
body = "Hello Ingrid\n\nWho are you?\n\nBest regards",
files = files,
)
* Send more than one file.
.. code-block:: python
files = (
'/home/mau/file1.epub',
'/home/mau/file2.epub',
)
* If your client email used `mbox` format, we can save in any path into your email client configuration.
.. code-block:: python
path_save = '/home/mau/.thunderbird/7iznrbyw.default/Mail/Local Folders/LibreOffice'
message = dict(
to = 'ingrid.bergman@email.net',
subject = 'I love you',
body = "Hello Ingrid\n\nWho are you?\n\nBest regards",
path = path_save
)
app.email.send(SERVER, message)
* All emails always send in other thread.