code: def create_attachments(attachment_files):
      
      attachments = []
      for filename, filedata in attachment_files.items():
  
          if isinstance(filedata, dict):
              content = filedata.get('file', None)
              mimetype = filedata.get('mimetype', None)
              headers = filedata.get('headers', None)
          else:
              content = filedata
              mimetype = None
              headers = None
  
          opened_file = None
  
          if isinstance(content, string_types):
              # `content` is a filename - try to open the file
              opened_file = open(content, 'rb')
              content = File(opened_file)
  
          attachment = Attachment()
          if mimetype:
              attachment.mimetype = mimetype
          attachment.headers = headers
          attachment.file.save(filename, content=content, save=True)
  
          attachments.append(attachment)
  
          if opened_file is not None:
              opened_file.close()
  
      return attachments
docs: Create Attachment instances from files
  
      attachment_files is a dict of:
          * Key - the filename to be used for the attachment.
          * Value - file-like object, or a filename to open OR a dict of {'file': file-like-object, 'mimetype': string}
  
      Returns a list of Attachment objects