动态 版块 发帖 消息 我的
xwylt
书山有路勤为径,学海无涯苦作舟
lytcreateLv13   
django生成excel并作为邮件附件推送     
1、生成表格并保存

2、发送邮件,并添加附件


file_path = 'file.xls'
ws.save(file_path)
connection = mail.get_connection()
connection.open()
email1 = mail.EmailMessage(
            '测试,谢谢!',
            '没有内容',
            '发件人@com.cn',
            ['收件人邮箱'],
            connection=connection,
        )
text = open(file_path, 'rb').read()
file_name = os.path.basename(file_path)
b = make_header([(file_name, 'utf-8')]).encode('utf-8')
email1.attach(b,text)
email1.send()
connection.close()
效果:



注意在部署环境下,file_path需要写入绝对路径:

file_path = 'D:/wwwroot/Apache24/htdocs/file/PFMEA_' + title +'_RPL=1.xls'


 0  已被阅读了47次  楼主 2021-04-06 16:29:23
回复列表

回复:django生成excel并作为邮件附件推送

Powered by Xwylt.com
© 2020-2021 lytcreate
您的IP:18.232.53.118,2021-04-23 01:17:05,Processed in 0.00835 second(s).
Powered by HadSky
书山有路勤为径,学海无涯苦作舟
已有0次打赏