【发布时间】:2010-08-03 07:26:05
【问题描述】:
如何使用谷歌应用引擎 (Python) 将位于 Web URL 上的文件附加到电子邮件?
我的文件位于:http://www.abc.com/files/file.pdf
我想将此附加到电子邮件中并将其发送给应用引擎上的用户。我该怎么做?
【问题讨论】:
标签: google-app-engine email url attachment
如何使用谷歌应用引擎 (Python) 将位于 Web URL 上的文件附加到电子邮件?
我的文件位于:http://www.abc.com/files/file.pdf
我想将此附加到电子邮件中并将其发送给应用引擎上的用户。我该怎么做?
【问题讨论】:
标签: google-app-engine email url attachment
要发送附件,您必须使用包含文件名和文件内容的二值元组列表填充电子邮件的附件字段。来自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)])
【讨论】: