Skip to content

Instantly share code, notes, and snippets.

@NlsNi
Created February 15, 2017 01:30
Show Gist options
  • Save NlsNi/ba96f49d4cf6fc2fd58a9aa7a393bb41 to your computer and use it in GitHub Desktop.
Save NlsNi/ba96f49d4cf6fc2fd58a9aa7a393bb41 to your computer and use it in GitHub Desktop.
send rich text email with python
import smtplib
from email.mime.text import MIMEText
from email.header import Header
def mail(htm):
sender = 'sender@163.com'
receiver = 'receiver@163.com'
subject = 'test'
smtpserver = 'smtp.163.com'
username = 'sender@163.com'
password = 'password'
msg = MIMEText(htm, 'html', 'utf-8')
msg['Subject'] = Header(subject, 'UTF-8')
msg['From'] = sender
msg['To'] = receiver
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment