Package web2py :: Package gluon :: Module tools :: Class Mail :: Class Attachment |
[hide private]
[frames] | no frames]

# Class Attachment

source code

    email.message.Message --+
                            |
     email.mime.base.MIMEBase --+
                                |
                               Mail.Attachment

Email attachment

Arguments:

       payload: path to file or file-like object with read() method
       filename: name of the attachment stored in message; if set to
                 None, it will be fetched from payload path; file-like
                 object payload must have explicit filename specified
       content_id: id of the attachment; automatically contained within
                   < and >
       content_type: content type of the attachment; if set to None,
                     it will be fetched from filename using gluon.contenttype
                     module
       encoding: encoding of all strings passed to this function (except
                 attachment body)

Content ID is used to identify attachments within the html body; in example, attached image with content ID 'photo' may be used in html message as a source of img tag <img src="cid:photo" />.

Examples:

       #Create attachment from text file:
       attachment = Mail.Attachment('/path/to/file.txt')

       Content-Type: text/plain
       MIME-Version: 1.0
       Content-Disposition: attachment; filename="file.txt"
       Content-Transfer-Encoding: base64

       SOMEBASE64CONTENT=

       #Create attachment from image file with custom filename and cid:
       attachment = Mail.Attachment('/path/to/file.png',
                                        filename='photo.png',
                                        content_id='photo')

       Content-Type: image/png
       MIME-Version: 1.0
       Content-Disposition: attachment; filename="photo.png"
       Content-Id: <photo>
       Content-Transfer-Encoding: base64

       SOMEOTHERBASE64CONTENT=

Instance Methods | [hide private]
__init__(self, payload, filename=1, content_id=1, content_type=1, encoding=`'``utf-8``'`) This constructor adds a Content-Type: and a MIME-Version: header. | source code
Inherited from `email.message.Message`: `__contains__`, `__delitem__`, `__getitem__`, `__len__`, `__setitem__`, `__str__`, `add_header`, `as_string`, `attach`, `del_param`, `get`, `get_all`, `get_boundary`, `get_charset`, `get_charsets`, `get_content_charset`, `get_content_maintype`, `get_content_subtype`, `get_content_type`, `get_default_type`, `get_filename`, `get_param`, `get_params`, `get_payload`, `get_unixfrom`, `has_key`, `is_multipart`, `items`, `keys`, `replace_header`, `set_boundary`, `set_charset`, `set_default_type`, `set_param`, `set_payload`, `set_type`, `set_unixfrom`, `values`, `walk` Inherited from `email.message.Message` (private): `_get_params_preserve`

Method Details | [hide private]

### __init__(self, payload, filename=1, content_id=1, content_type=1, encoding=`'``utf-8``'`) (Constructor) | source code
This constructor adds a Content-Type: and a MIME-Version: header. The Content-Type: header is taken from the _maintype and _subtype arguments. Additional parameters for this header are taken from the keyword arguments. Overrides: email.mime.base.MIMEBase.__init__ (inherited documentation)