Skip to content

Instantly share code, notes, and snippets.

@ntuaha
Created May 1, 2020 11:58
Show Gist options
  • Save ntuaha/1264d8a3009939160394774f23e2fd62 to your computer and use it in GitHub Desktop.
Save ntuaha/1264d8a3009939160394774f23e2fd62 to your computer and use it in GitHub Desktop.
gmail smtp
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