views:

26

answers:

1

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?

+2  A: 

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="[email protected]",
               to="[email protected]",
               subject="The file you wanted",
               body="Here is the file you wanted",
               attachments=[("The file name.pdf", document)])
Gab Royer
Thanks! worked perfectly!
demos