Created
February 15, 2017 01:30
-
-
Save NlsNi/ba96f49d4cf6fc2fd58a9aa7a393bb41 to your computer and use it in GitHub Desktop.
send rich text email with python
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 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