Skip to content

Instantly share code, notes, and snippets.

@kristovatlas
Created September 16, 2020 17:08
Show Gist options
  • Save kristovatlas/c4ff12250a90cced0f832be48a335596 to your computer and use it in GitHub Desktop.
Save kristovatlas/c4ff12250a90cced0f832be48a335596 to your computer and use it in GitHub Desktop.
Send GMail
#python3
# Usage: emailer.send(recipient_email, mail_subject, message)
#https://stackabuse.com/how-to-send-emails-with-gmail-using-python/
import smtplib
gmail_user = 'username@gmail.com'
gmail_password = 'password_goes_here'
sent_from = gmail_user
def send(recipients, subject, body):
email_text = """From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(recipients), subject, body)
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(sent_from, recipients, email_text)
server.close()
print('Email sent!')
except:
print('Something went wrong...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment