smtplib
email.mime.text MIMEText
email.parser Parser
email.mime.multipart MIMEMultipart
sender = receivers = []
message = MIMEMultipart()
message[] = sender
message[] = receivers
subject = message[] = subject
body = (,,=).read()
message.attach(MIMEText(body,))
server = smtplib.SMTP()
server.starttls()
server.login(sender,)
text1 = message.()
server.sendmail(sender,receivers,text1)
server.quit()conf.txt文档内容如下修改后代码#-*- encoding: utf-8 -*-#-*- encoding: gbk -*-import smtplibfrom email.mime.text import MIMETextfrom email.parser import Parserfrom email.mime.multipart import MIMEMultipartsender = 'wangtingdetime@qq.com'receivers = ['2718339969@qq.com']message = MIMEMultipart()message['From'] = sendermessage['To'] = receiverssubject = 'my first email'message['Subject'] = subjectbody = open('conf.txt','rt',encoding='utf8').read()#print(type(body))message.attach(MIMEText(body,'plain'))server = smtplib.SMTP('smtp.qq.com')server.starttls()server.login(sender,"fojczcjqnawxcdhh")str = str()for i in message: str = str + i#print(str)#for p in message:# print(p)#print(type(text1))server.sendmail(sender,receivers,str)server.quit()
添加回答
举报
0/150
提交
取消