Created
May 1, 2020 11:58
-
-
Save ntuaha/1264d8a3009939160394774f23e2fd62 to your computer and use it in GitHub Desktop.
gmail smtp
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
from email.mime.text import MIMEText | |
import smtplib | |
import os | |
def main(): | |
gmailUser = os.environ['EMAIL_USER'] | |
gmailPasswd = os.environ['EMAIL_PWD'] | |
message = MIMEText(f'lol', 'plain', 'utf-8') | |
message['Subject'] = 'hello world' | |
message['From'] = gmailUser | |
# to multi-recipents | |
# emails = [t.split(',') for t in to] | |
# message['To'] = ','.join([emails]) | |
message['To'] = '[email protected]' | |
# Set smtp | |
smtp = smtplib.SMTP("smtp.gmail.com:587") | |
smtp.ehlo() | |
smtp.starttls() | |
smtp.login(gmailUser, gmailPasswd) | |
# Send msil | |
smtp.sendmail(message['From'], message['To'], message.as_string()) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment