Hide
Python

The Attachment Class

An instance of the Attachment class represents an attachment to an email message, and includes attributes for specifying the filename, payload, and Content-ID for the attachment.

Attachment is provided by the google.appengine.api.mail module.

  1. Introduction
  2. Attachment()
  3. Properties:

Introduction

An Attachment object is largely interchangeable with a (filename, payload) tuple.

Note that the behavior is a bit asymmetric with respect to unpacking and equality comparison. An Attachment object without a content-id attribute is equivalent to a (filename, payload) tuple. An Attachment with a content-id unpacks to a (filename, payload) tuple, but compares unequally to that tuple.

Thus, the following comparison will succeed:

attachment = mail.Attachment('foo.jpg', 'data')
filename, payload = attachment
attachment == filename, payload

...while the following will fail:

attachment = mail.Attachment('foo.jpg', 'data', content_id='')
filename, payload = attachment
attachment == filename, payload

The following comparison will pass though:

attachment = mail.Attachment('foo.jpg', 'data', content_id='')
attachment == (attachment.filename,
               attachment.payload,
               attachment.content_id)

Constructor

class Attachment (filename, payload, content_id=None)

An attachment to an email message. The fields of the Attachment object can be initialized using arguments passed to the constructor. Fields can also be set after construction using attributes of the instance.

Properties

The Attachment class provides the following properties:

filename

The name of the attachment.

payload

The name of the attachment. 7bit is the default MIME encoding.

content_id=None

Optional. The Content-ID for this attachment. The Content-ID must be enclosed in angle brackets (e.g. <my-content-id>).