Attaching Files to Email in App Engine?

徘徊边缘 提交于 2019-12-05 02:04:52

问题


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

I have the file located at say: 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?


回答1:


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)])


来源:https://stackoverflow.com/questions/3394397/attaching-files-to-email-in-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!