Created
September 16, 2020 17:08
-
-
Save kristovatlas/c4ff12250a90cced0f832be48a335596 to your computer and use it in GitHub Desktop.
Send GMail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
# Usage: emailer.send(recipient_email, mail_subject, message) | |
#https://stackabuse.com/how-to-send-emails-with-gmail-using-python/ | |
import smtplib | |
gmail_user = '[email protected]' | |
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