Skip to page content Skip to main navigation
English | Site Directory

e.g. "templates" or "datastore"

# Attachments

An email message can include file attachments. The `attachments` field of an email message accepts a list of two-value tuples, one tuple for each attachment. The first element of the 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 db

    class DocFile(db.Model):
      doc_name = StringProperty()
      doc_file = BlobProperty()

    q = db.GqlQuery("SELECT * FROM DocFile WHERE doc_name = :1", myname)
    results = q.fetch(1)
    if results:
      doc = results[0]
      mail.send_mail(sender="support@example.com",
                    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)])

Only certain types of files are allowed as attachments. The filename of the attachment describes the type of the file.

## Allowed Attachment Types

For security purposes, a file attached to an email messages must be of one of the allowed file types, and its filename must end with an extension that corresponds with its type. The attachment is sent with a MIME type determined by the filename extension.

The following is a list of MIME types and their corresponding filename extensions allowed for file attachments to an email message.

MIME Type | Filename Extensions
--- | ---
image/x-ms-bmp | bmp
text/css | css
text/comma-separated-values | csv
image/gif | gif
text/html | htm html
image/jpeg | jpeg jpg jpe
application/pdf | pdf
image/png | png
application/rss+xml | rss
text/plain | text txt asc diff pot
image/tiff | tiff tif
image/vnd.wap.wbmp | wbmp