Created
May 24, 2021 11:09
-
-
Save Tomen/663be20e627879df27e2c6a6117a69af to your computer and use it in GitHub Desktop.
Python Gmail Send Client
This file contains 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
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