.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "automation/send_mails.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_automation_send_mails.py: Send many mails =============== Send mail to students. The script consider two columns from one spreadsheets. The first one is about the receivers, the second one about the customized message for each of them. .. GENERATED FROM PYTHON SOURCE LINES 12-13 logging et import .. GENERATED FROM PYTHON SOURCE LINES 13-20 .. code-block:: default import os import warnings from pyquickhelper.loghelper import fLOG fLOG(OutputPrint=True) from ensae_teaching_cs.automation_students import enumerate_feedback, enumerate_send_email import pymmails .. GENERATED FROM PYTHON SOURCE LINES 21-22 On définit le contenu du mail. .. GENERATED FROM PYTHON SOURCE LINES 22-41 .. code-block:: default cc = [] sujet = "Question de code - ENSAE 1A - projet de programmation" col_name = None # "mail" col_mail = "mail" columns = ["sujet", "Question de code"] col_group = "groupe" delay_sending = False test_first_mail = False # regarder le premier mail avant de les envoyer skip = 0 # to start again after a failure only = None skiprows = 1 folder = os.path.normpath(os.path.abspath(os.path.join( *([os.path.dirname(__file__)] + ([".."] * 5) + ["_data", "ecole", "ENSAE", "2017-2018", "1A_projet"])))) student = os.path.join(folder, "ENSAE 1A - projet python.xlsx") if not os.path.exists(student): raise FileNotFoundError(student) .. GENERATED FROM PYTHON SOURCE LINES 42-43 début commun .. GENERATED FROM PYTHON SOURCE LINES 43-58 .. code-block:: default begin = """ Bonjour, """ + \ """ Bonjour, Voici les questions de code. Celles-ci sont extraites des programmes que vous m'avez transmis. Les noms de fonctions que j'utilise y font référence quand je ne recopie pas le code. La réponse est souvent liée à la performance. """.replace("\n", " ") .. GENERATED FROM PYTHON SOURCE LINES 59-60 fin commune .. GENERATED FROM PYTHON SOURCE LINES 60-68 .. code-block:: default end = """ """.replace("\n", " ") + \ """ Xavier """ .. GENERATED FROM PYTHON SOURCE LINES 69-70 Lecture des de la feuille Excel .. GENERATED FROM PYTHON SOURCE LINES 70-84 .. code-block:: default import pandas df = pandas.read_excel(student, sheet_name=0, skiprows=skiprows, engine='openpyxl') if len(df.columns) < 4: raise ValueError("Probably an issue while reading the spreadsheet:\n{0}\n{1}".format( df.columns, df.head())) if len(" ".join(df.columns).split("Unnamed")) > 4: raise ValueError("Probably an issue while reading the spreadsheet:\n{0}\n{1}".format( df.columns, df.head())) fLOG("shape", df.shape) fLOG("columns", df.columns) .. GENERATED FROM PYTHON SOURCE LINES 85-86 mot de passe .. GENERATED FROM PYTHON SOURCE LINES 86-91 .. code-block:: default from pyquickhelper.loghelper import get_keyword user = get_password("gmail", "ensae_teaching_cs,user") pwd = get_password("gmail", "ensae_teaching_cs,pwd") .. GENERATED FROM PYTHON SOURCE LINES 92-96 On envoie les mails. Le paramètre delay_sending retourne une fonction qu'il suffit d'exécuter pour envoyer le mail. Si mailbox est None, la fonction affiche les résultats mais ne fait rien. .. GENERATED FROM PYTHON SOURCE LINES 96-113 .. code-block:: default fLOG("connect", user) mailbox = pymmails.sender.create_smtp_server("gmail", user, pwd) fLOG("send") # remplacer mailbox par None pour voir le premier mail sans l'envoyer mails = enumerate_send_email(mailbox if not test_first_mail else None, sujet, user + "@gmail.com", df, exc=True, fLOG=fLOG, delay_sending=delay_sending, begin=begin, end=end, skip=skip, cc=cc, only=only, col_group=col_group, col_name=col_name, col_mail=col_mail, cols=columns) for i, m in enumerate(mails): fLOG("------------", m) .. GENERATED FROM PYTHON SOURCE LINES 114-115 fin .. GENERATED FROM PYTHON SOURCE LINES 115-117 .. code-block:: default mailbox.close() fLOG("Done") .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_automation_send_mails.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: send_mails.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: send_mails.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_