【发布时间】:2019-11-08 12:04:36
【问题描述】:
我正在使用 flask-mail 发送一封包含 pdf 文档作为附件的邮件, 问题是当我在我的电子邮件中收到它时,文档的名称结果是“noname”(没有任何扩展名),即使该文档是可下载和可读的,但仍有一些特殊情况(可能是十分之一)文档不能被打开(可能是因为没有设置扩展名)。
def send_mail_flask_to_user(self, doc_name, document_id, email,approve):
app.config.update(self.mail_settings)
mail = Mail(app)
with app.app_context():
msg = Message(sender=app.config.get(
"MAIL_USERNAME"), recipients=[email])
msg.subject = '{} Coriolis Tech'.format(doc_name)
msg.body=""" Dear {},
your request for {} has be approved and generated,please find the attachment for the same""".format(email.split('.')[0],doc_name)
working_dir=os.getcwd()
link = "https://docs.google.com/document/d/{}/".format(document_id)
if (approve==True):
with open(working_dir+"/generated_docs/"+document_id+".pdf",'rb') as fh:
msg.attach(working_dir+"/"+document_id+".pdf","application/pdf",fh.read())
elif(approve==False):
msg.body=""" Your {} is rejected ,contact Division of Human Resource Coriolis Technologies to know more""".format(doc_name)
mail.send(msg)
这个问题只在 Ubuntu 14.04 上仍然存在,因为它在 Windows 机器上运行良好
【问题讨论】:
标签: python-3.x flask ubuntu-14.04 flask-mail