.. _sendemailrst: ========== Send email ========== .. only:: html **Links:** :download:`notebook `, :downloadlink:`html `, :download:`PDF `, :download:`python `, :downloadlink:`slides `, :githublink:`GitHub|_doc/notebooks/send_email.ipynb|*` Send mails with attachments from a notebook. .. code:: ipython3 with open("erty.txt", "w") as f: f.write("try.try.try") .. code:: ipython3 import pymmails .. code:: ipython3 server = pymmails.create_smtp_server("gmail", "xavier.somebody@gmail.com", "pwd") In fonction `create_smtp_server `__, the string ``gmail`` is replaced by ``smtp.gmail.com:567`` (tls version). By default, the server cannot be accessed unless IMAP is enabled (see `Problems sending mail with POP or IMAP `__). You can usually find this string by searching on internet for ``your provider smtp server``, you find pages such as `configuration des serveurs sortants et entrants des principaux comptes mails `__. However, by doing this, you need to send your password. You should remove your password wherever it appears as soon as you don’t need it anymore. If you forget, I advise you to change it. .. code:: ipython3 pymmails.send_email(server, "xavier.somebody@gmail.com", "xavier.somebodyelse@else.com", "results", "body", attachements = [ "erty.txt" ]) .. code:: ipython3 server.quit() .. parsed-literal:: (221, b'2.0.0 closing connection e18sm17176289wjz.27 - gsmtp') Module `keyring `__ should be used to store password instead of letting them accessible in the notebook.