在App Engine中将文件附加到电子邮件吗? [英] Attaching Files to Email in App Engine?

查看:95
本文介绍了在App Engine中将文件附加到电子邮件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Google App Engine(Python)将Web URL上的文件附加到电子邮件?

How do I attach a file located on Web URL to an email using google app engine (Python)?

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

我想将此邮件附加到电子邮件上,然后发送给应用引擎上的用户.我该怎么办?

I want to attach this to an email and send it to a user on app engine. How do I do this?

推荐答案

要发送附件,您必须在电子邮件的附件字段中填充一个包含文件名和文件内容的二值tupless列表.来自此处

To send attachment you have to fill the attachment field of an email message with a list of two-value tupless containing the file name and the file content. From 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)])

这篇关于在App Engine中将文件附加到电子邮件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆