如何在使用Google应用引擎(Python)时将位于Web URL上的文件附加到电子邮件中?
假设我有一个位于以下URL的文件:http://www.abc.com/files/file.pdf
我想将其附加到电子邮件并发送给应用引擎上的用户。我该怎么做?
如何在使用Google应用引擎(Python)时将位于Web URL上的文件附加到电子邮件中?
假设我有一个位于以下URL的文件:http://www.abc.com/files/file.pdf
我想将其附加到电子邮件并发送给应用引擎上的用户。我该怎么做?
要发送附件,您需要在电子邮件消息的附件字段中填写一个包含文件名和文件内容的两个值元组列表。详情请见此处。
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)])