在App Engine中将文件附加到电子邮件?

dem*_*mos 4 email url google-app-engine attachment

如何使用谷歌应用引擎(Python)将位于Web URL上的文件附加到电子邮件中?

我的文件位于:http://www.abc.com/files/file.pdf

我想将此附加到电子邮件中并将其发送给应用引擎上的用户.我该怎么做呢?

Gab*_*yer 5

要发送附件,您必须填写电子邮件的附件字段,其中包含包含文件名和文件内容的双值tupless列表.从这里开始

from google.appengine.api import urlfetch
from google.appengine.api import mail  

url = "http://www.abc.com/files/file.pdf" 
result = urlfetch.fetch(url)

if result.status_code == 200: 
  document = result.content

mail.send_mail(sender="youremail@yourdomain.com",
               to="receiver@hisdomain.com",
               subject="The file you wanted",
               body="Here is the file you wanted",
               attachments=[("The file name.pdf", document)])
Run Code Online (Sandbox Code Playgroud)