def attach_file(self, filename, content_type=None,
                    content_id=None):
        '''Attach a file to the message given a filename.

        :param filename: Name of the file to attach.
        :param content_type: mimetype of the data. It will be guessed from the
            filename if not provided.
        :param content_id: ContentID URL of the attachment.  A RFC 2392-
            compliant URL for the attachment that allows it to be referenced
            from inside the body of the message.  Must start with 'cid:'
         '''
        # Open the file, grab the filename, detect content type
        name = os.path.basename(filename)
        if not name:
            err = 'Filename not found in path: {0}'
            raise MessageError(err.format(filename))
        with open(filename, 'rb') as f:
            data = f.read()
        self.attach_binary(data, name, content_type=content_type,
                           content_id=content_id)
def attach_file ( self , filename , content_type = None , content_id = None ) : name = os . path . basename ( filename ) if not name : err = 'Filename not found in path: {0}' raise MessageError ( err . format ( filename ) ) with open ( filename , 'rb' ) as f : data = f . read ( ) self . attach_binary ( data , name , content_type = content_type , content_id = content_id )
Attach a file to the message given a filename.

        :param filename: Name of the file to attach.
        :param content_type: mimetype of the data. It will be guessed from the
            filename if not provided.
        :param content_id: ContentID URL of the attachment.  A RFC 2392-
            compliant URL for the attachment that allows it to be referenced
            from inside the body of the message.  Must start with 'cid:'