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 smtplib
from email.mime.text import MIMEText
from email.parser import Parser
from email.mime.multipart import MIMEMultipart
sender = 'wangtingdetime@qq.com'
receivers = ['2718339969@qq.com']
message = MIMEMultipart()
message['From'] = sender
message['To'] = receivers
subject = 'my first email'
message['Subject'] = subject
body = 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()
姜皓
清波