Created
July 16, 2019 20:47
-
-
Save miklevin/fdecdc210319899754fd596c92c0cca4 to your computer and use it in GitHub Desktop.
Bare minimum to send GMails
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
import smtplib | |
from pathlib import Path | |
tos = Path("emails_test.txt").read_text().strip() | |
tos_list = tos.split('\n') | |
tos = ", ".join(tos_list) | |
SUBJECT = 'TEST MAIL' | |
TEXT = 'Here is a message from python.' | |
# Gmail Sign In | |
gmail_sender = '[who_are_you]@gmail.com' | |
gmail_passwd = Path("google_app_passwd.txt").read_text().strip() | |
server = smtplib.SMTP('smtp.gmail.com', 587) | |
server.ehlo() | |
server.starttls() | |
server.login(gmail_sender, gmail_passwd) | |
BODY = '\r\n'.join(['To: %s' % tos, | |
'From: %s' % gmail_sender, | |
'Subject: %s' % SUBJECT, | |
'', TEXT]) | |
try: | |
server.sendmail(gmail_sender, tos_list, BODY) | |
print ('email sent') | |
except: | |
print ('error sending mail') | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment