2021-06-22 22:54:25 -05:00
|
|
|
|
|
|
|
Email
|
|
|
|
-----
|
|
|
|
|
|
|
|
Remember, always import library.
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
import easymacro as app
|
|
|
|
|
|
|
|
|
2021-06-30 14:29:02 -05:00
|
|
|
**IMPORTANT:** Always save your config the more security way possible.
|
|
|
|
|
|
|
|
|
2021-06-22 22:54:25 -05:00
|
|
|
Send email
|
|
|
|
^^^^^^^^^^
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
2021-06-30 14:29:02 -05:00
|
|
|
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.send_email(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'
|
|
|
|
|
2021-06-30 22:26:08 -05:00
|
|
|
* We can send too more than one message.
|
2021-06-30 14:29:02 -05:00
|
|
|
|
|
|
|
.. 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',
|
2021-06-30 22:26:08 -05:00
|
|
|
body = "Hello Sophia\n\nWho are you?\n\nBest regards",
|
2021-06-30 14:29:02 -05:00
|
|
|
)
|
|
|
|
messages = (message1, message2)
|
|
|
|
|
|
|
|
app.send_email(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',
|
|
|
|
)
|
|
|
|
|
2021-06-30 22:26:08 -05:00
|
|
|
* 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.send_email(SERVER, message)
|
|
|
|
|
2021-06-30 14:29:02 -05:00
|
|
|
|
|
|
|
* All emails always send in other thread.
|
2021-06-22 22:54:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
.. _cryptography: https://github.com/pyca/cryptography
|