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

时间:2010-08-03 07:26:05

标签: google-app-engine email url attachment

如何使用google app engine(Python)将位于网址上的文件附加到电子邮件中?

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

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

1 个答案:

答案 0 :(得分:5)

要发送附件,您必须填写电子邮件的附件字段,其中包含包含文件名和文件内容的双值tupless列表。来自here

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)])
相关问题