您的位置:首页 > 编程语言 > Python开发

python 利用smtp发送文本邮件

2015-01-07 18:37 633 查看
废话不多说,直接贴代码

#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText
from email.header import Header

sender = 'xxxx@yyy.com'
receiver = 'zzzzz@qq.com'
username = 'login_user'
password = 'login_passwd'

def sendMail(content,subject):
msg = MIMEText(content,_subtype='plain',_charset='gb2312')
msg['Subject'] = Header(subject, 'utf-8')
smtp = smtplib.SMTP()
#smtp.set_debuglevel(1)
smtp.connect('smtp.your.com','587')
smtp.starttls()
smtp.login(username,password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()

sendMail("this is a python send email test","hello python")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: