开发者

Attaching Files to Email in App Engine?

开发者 https://www.devze.com 2023-01-09 19:18 出处:网络
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

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 t开发者_StackOverflowo attach this to an email and send it to a user on app engine. How do I do this?


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号