I made this script to get data from a google form (in the excel format exported from the google sheets associated with the google form) and send them to the ones who answered to the form, getting their emails.
import pandas as pd from random import choice import os import smtplib # put you password here password = "xxxxxxxxxxxxxxx" name = [] destinatari = [] punteggio = [] df = pd.read_excel("4ce13.xlsx") for e in df["Indirizzo email"]: destinatari.append(str(e)) for n in df["Nome"]: name.append(str(n)) for n in df["Punteggio"]: punteggio.append(str(n)) # attenzione non usare è, ma e' schema = """Caro {} email {} Il tuo punteggio e' {}""" def new_schema(schema): global messaggi numeri = [1, 3, 5, 7] messaggi = [] soluzioni = [] # a ogni studente mette il nome personalizzato for n, s in enumerate(name): num1, num2 = choice(numeri), choice(numeri) traccia = schema.format(s, destinatari[n], punteggio[n]) messaggi.append(traccia) soluzioni.append( s + "\n" + traccia + "[S: " + str(num1 * num2) + "]\n\n") with open("soluzioni.txt", "w") as file: file.write("".join(soluzioni)) print(*soluzioni) os.startfile("soluzioni.txt") print(messaggi) print(destinatari) print(name) def manda_email(): global messaggi for n, mess in enumerate(messaggi): server = smtplib.SMTP("smtp.gmail.com", 587) server.ehlo() server.starttls() server.ehlo() # put your email here server.login("[email protected]", password) server.sendmail( "[email protected]", destinatari[n], messaggi[n]) server.quit() def send(): manda_email() import tkinter as tk root = tk.Tk() label = tk.Label( root, text="Click the button to send \nthe personal code to the stundets", bg="gold") label.pack() button = tk.Button(root, text="Send the email", command=send) button.pack() button2 = tk.Button(root, text="See new schema", command=lambda: new_schema(text.get("0.0", tk.END))) button2.pack() text = tk.Text(root) text.pack() text.insert("0.0", schema) new_schema(text.get("0.0", tk.END)) root.mainloop()
Video with code explanation to send mail from Google forms data
Subscribe to the newsletter for updates
Tkinter templates
My youtube channel
Twitter: @pythonprogrammi - python_pygame