发邮件实例

#!/usr/bin/env python3
# -*-conding:utf-8-**
# __Author__:'liudong'
def sendmail():
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

msg = MIMEText('邮件内容', 'plain', 'utf-8')
msg['From'] = formataddr(["xxx", 'xxxxx7@163.com'])
msg['To'] = formataddr(["走人", 'xxxxxx7@163.com'])
msg['Subject'] = "主题"

server = smtplib.SMTP("smtp.163.com", 25)
server.login("xxxxxx", "password")
server.sendmail('xxxxxx', ['xxxxxx', ], msg.as_string())
server.quit()

# 发送邮件实例
sendmail()
posted @ 2016-10-29 09:48  ld1977  阅读(97)  评论(0)    收藏  举报