Skip to content

Instantly share code, notes, and snippets.

@Tomen
Created May 24, 2021 11:09
Show Gist options
  • Save Tomen/663be20e627879df27e2c6a6117a69af to your computer and use it in GitHub Desktop.
Save Tomen/663be20e627879df27e2c6a6117a69af to your computer and use it in GitHub Desktop.
Python Gmail Send Client
class GmailClient:
def __init__(self, config):
self._email = config["email"]
self._password = config["password"]
def send_email(self, receiver_emails, subject, body):
sender_email = self._email
#https://security.google.com/settings/security/apppasswords
password = self._password
email_text = """\
From: %s
To: %s
Subject: %s
%s
""" % (sender_email, ", ".join(receiver_emails), subject, body)
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(sender_email, password)
server.sendmail(sender_email, receiver_emails, email_text)
server.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment