Skip to content

Instantly share code, notes, and snippets.

@walkingmask
Created December 15, 2017 13:56
Show Gist options
  • Select an option

  • Save walkingmask/33a4cea9177d0050a57727c28b96cb66 to your computer and use it in GitHub Desktop.

Select an option

Save walkingmask/33a4cea9177d0050a57727c28b96cb66 to your computer and use it in GitHub Desktop.
A example of sending email with gmail.
# -*- coding: utf-8 -*-
from email.mime.text import MIMEText
from email.utils import formatdate
import smtplib
addr = ""
pswd = ""
subj = ""
body = ""
msg = MIMEText(body)
msg['Subject'] = subj
msg['From'] = addr
msg['To'] = addr
msg['Date'] = formatdate()
try:
with smtplib.SMTP('smtp.gmail.com', 587) as smtps:
smtps.ehlo()
smtps.starttls()
smtps.ehlo()
smtps.login(addr, pswd)
smtps.sendmail(addr, addr, msg.as_string())
smtps.close()
print("Successfully sent email")
except Exception as e:
print("Error: unable to send email")
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment