import smtplib
from email.mime.text import MIMEText
from email.header import Header
#发送邮件的函数 参数的意思分别是 发件人邮箱、收件人邮箱、主题、附件、消息内容
def SendEmail(fromAdd, toAdd, subject, attachfile, htmlText):
strFrom = fromAdd;
strTo = toAdd;
msg =MIMEText(htmlText);
msg['Content-Type'] = 'Text/HTML';
msg['Subject'] = Header(subject,'gb2312');
msg['To'] = strTo;
msg['From'] = strFrom;
#链接QQ邮箱服务器
smtp = smtplib.SMTP('smtp.qq.com');
#登录您的邮箱
smtp.login('1806007002@qq.com','12345678');
try:
#执行发送
smtp.sendmail(strFrom,strTo,msg.as_string());
finally:
smtp.close;
#主函数,脚本从这里开始执行
if __name__ == "__main__":
#,SendEmail是函数名称后面的括号中是函数的参数
SendEmail("1806007002@qq.com","1806007002@qq.com","","hello","hello world");
python写的自动发送QQ邮件的脚本
5星 · 超过95%的资源 需积分: 50 182 浏览量
2013-08-18
00:32:27
上传
评论 6
收藏 646B RAR 举报
苏生米沿
- 粉丝: 616
- 资源: 40
- 1
- 2
前往页