smtp发送邮件源码

来源:互联网 发布:韩寒与郭敬明知乎 编辑:程序博客网 时间:2024/05/20 12:48
import smtplibfrom email.mime.text import MIMETextfrom email.header import Headerimport timedef email():    #发送邮箱服务器    smtpserver = "smtp.163.com"    #发送邮箱的账号/密码    user= "你的账号@163.com"    password="你的密码"    #发送邮箱    sender="你的账号@163.com"    #收件箱    receiver = "收件人的账号@qq.com"   #发送主题    subject = "这是给你的"    #编写HTML类型的邮件正文    msg = MIMEText("<html><h1>这是轰炸邮件啊!</h1></html>","html","utf-8")    msg['Subject'] = Header(subject, 'utf-8')    #这两个参数必须要,不然就会出现554的错误,不然少参数    msg['from']=sender    msg['to']=receiver            #连接发送邮箱    smtp = smtplib.SMTP()    smtp.connect(smtpserver)    smtp.login(user,password)    smtp.sendmail(sender, receiver, msg.as_string())    smtp.quit()    print("执行第",i,"次,成功!")    time.sleep(2)    #print("发送失败!")i=1while  i:    email()    i +=1    if i >2000:        break