I was looking for a solution to send emails during graph executions, and I came up with this one below. The code allows to send multiple email at once and it could be used for lots of stuff!
But before you start you’ll need to allow 3rd party app to use gmail. Hope you find it useful too! .
1. open your gmail account settings
2. go to the security page
3. allow for less secure app
4. now you’re ready to go! just copy paste the code below and customize it as you need
import smtplib sender = "email@example.com" receivers = ["firstname.lastname@example.org", "email@example.com"] password = "the password of your valid gmail account" subject = "sending email from Dynamo 😎" body = "the body of the email" email_text = """\ From: %s To: %s Subject: %s %s """ % (sender, ", ".join(receivers), subject, body) try: server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.ehlo() server.login(sender, password) server.sendmail(sender, receivers, email_text) server.close() OUT = "email sent" except: OUT = "something went wrong"