An email message can include file attachments. The
attachments field of
an email message accepts a list of either two-value tuples, or
If tuples are used, one tuple must be created for each attachment. The first element of each tuple is the filename to use for the attachment in the message, and the second element is the data, as a byte string.
from google.appengine.api import mail from google.appengine.ext import ndb class DocFile(ndb.Model): doc_name = ndb.StringProperty() doc_file = ndb.BlobProperty() q = ndb.gql("SELECT * FROM DocFile WHERE doc_name = :1", myname) results = q.fetch(1) if results: doc = results mail.send_mail(sender="firstname.lastname@example.org", to="Albert Johnson <Albert.Johnson@example.com>", subject="The doc you requested", body=""" Attached is the document file you requested. The example.com Team """, attachments=[(doc.doc_name, doc.doc_file)])
As a security measure to protect against viruses, you cannot send email attachments—or zip files—containing any of the following extensions: