还没有测试过
from email.mime.multipart import MIMEMultipart
form email.mime.image import MIMEImage
from email.mime.text import MIMEText
from smtplib import SMTPException
import smtplib
import codecs
import atext
import os
#引入atext.py文件
import atext
def message(sender_username,password,receiver):
user = sender_username
pwd = password
rec = receiver
with codecs.open('短文.txt', 'r',encoding = 'utf-8') as fp:
cont1 = fp.read()
fp = open('序号.txt','r')
a = int(fp.read)
fp.close()
content = cont1 + '<p><img src="cid:image1"></p>'
msg = MIMEMultipart()
msg['Subject'] = 'daliy lift 第%d天'%a
msg['From'] = user
msg['To'] = rec
msg.attach(MIMEText(content,'html','utf-8'))
with codecs.open('序号.txt','w',encoding = 'utf-8') as fp:
b = a+1
b = str(b)
fp.write(b)
path = os.getcwd()
os.chdir(r'D:\msg\图片')
fp = open('%s.jpg'%a,'rb')
msgImage = MIMEImage(fp.read())
fp.close()
msgImage.add_header('Content-ID','<image1>')
msg.attach(msgImage)
os.chdir(path)
try:
s = smtplib.SMTP.SMTP_SSL('smtp.qq.com', 465)
s.login(user,pwd)
s.sendmail(user,rec,msg.as_string())
print('send email success')
print('当前照片为第%张'%a)
except SMTPException
print('error!!!!!')
return
if __name__ == '__main__'
url = atext._url().strip('\n')
html = atext.download_page(url)
atext.parse_html(html)
sender_username = "99026866@qq.com"
password = 'Speed708097'
receiver = '1732681270@qq.com'
message(sender_username,password,receiver)