首页 > 解决方案 > 使用 smtplib 发送电子邮件时附件重复

问题描述

我正在使用 smtplib 从 csv 发送电子邮件,并尝试将 pdf 附加到每封电子邮件。但是,我最终每封电子邮件都有两个附件;有人可以帮我确定该附件在哪里被调用了两次吗?

                # Attach the pdf to the msg going by e-mail
                with open(EMAIL_FILE, "rb") as f:
                  attach = MIMEApplication(f.read(),_subtype="pdf")
                attach.add_header('Content-Disposition','attachment',filename=str(EMAIL_FILE))
                msg.attach(attach)
                mail.sendmail(EMAIL_FROM, EMAIL_TO, msg.as_string())

标签: pythonsmtplib

解决方案


推荐阅读