Sending email using python script

Hi all, :raised_hands:
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!
giphy

But before you start you’ll need to allow 3rd party app to use gmail. Hope you find it useful too! :peace_symbol:.

follow here:

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! :smiley: just copy paste the code below and customize it as you need

    import smtplib
    sender = "your_valid_gmail_here@gmail.com"
    receivers = ["steve.ballamer@gmail.com", "paris.hilton@gmail.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"
9 Likes