python 利用smtp发送文本邮件

来源:互联网 发布:mac关闭迅雷开机启动 编辑:程序博客网 时间:2024/05/29 21:30

废话不多说,直接贴代码

#!/usr/bin/pythonimport smtplibfrom email.mime.text import MIMETextfrom email.header import Headersender = '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")


0 0