python – 从blobstore发送数据作为GAE中的电子邮件附件
作者:互联网
为什么下面的代码不起作用?收到电子邮件,文件通过正确的文件名(它是一个.png文件).但是当我尝试打开文件时,它无法正确打开(Windows图库报告无法打开此照片或视频,并且文件可能不受支持,损坏或损坏).
当我使用blobstore_handlers.BlobstoreDownloadHandler的子类(基本上是GAE文档中的确切处理程序)和相同的blob键下载文件时,一切正常,Windows会读取图像.
还有一点信息 – 来自下载和电子邮件的二进制文件看起来非常相似,但长度略有不同.
任何人对如何从GAE blobstore发送电子邮件附件有任何想法?关于S / O也存在类似的问题,表明其他人已经遇到过这个问题,但似乎没有任何结论.
from google.appengine.api import mail
from google.appengine.ext import blobstore
def send_forum_post_notification():
blob_reader = blobstore.BlobReader('my_blobstore_key')
blob_info = blobstore.BlobInfo.get('my_blobstore_key')
value = blob_reader.read()
mail.send_mail(
sender='my.email@address.com',
to='my.email@address.com',
subject='this is the subject',
body='hi',
reply_to='my.email@address.com',
attachments=[(blob_info.filename, value)]
)
send_forum_post_notification()
解决方法:
我不明白为什么你使用元组作为附件.我用 :
message = mail.EmailMessage(sender = ......
message.attachments = [blob_info.filename,blob_reader.read()]
标签:python,google-app-engine,blobstore 来源: https://codeday.me/bug/20190629/1328814.html