exchangelib.services.create_attachment API documentation

# Module `exchangelib.services.create_attachment`

## Classes

`class CreateAttachment (*args, **kwargs)`
  Expand source code

      class CreateAttachment(EWSAccountService):
          """MSDN:
          https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/createattachment-operation
          """

          SERVICE_NAME = "CreateAttachment"
          element_container_name = f"{{{MNS}}}Attachments"
          cls_map = {cls.response_tag(): cls for cls in (FileAttachment, ItemAttachment)}

          def call(self, parent_item, items):
              return self._elems_to_objs(self._chunked_get_elements(self.get_payload, items=items, parent_item=parent_item))

          def _elem_to_obj(self, elem):
              return self.cls_map[elem.tag].from_xml(elem=elem, account=self.account)

          def get_payload(self, items, parent_item):
              payload = create_element(f"m:{self.SERVICE_NAME}")
              version = self.account.version
              if isinstance(parent_item, BaseItem):
                  # to_item_id() would convert this to a normal ItemId, but the service wants a ParentItemId
                  parent_item = ParentItemId(parent_item.id, parent_item.changekey)
              set_xml_value(payload, to_item_id(parent_item, ParentItemId), version=self.account.version)
              attachments = create_element("m:Attachments")
              for item in items:
                  set_xml_value(attachments, item, version=version)
              payload.append(attachments)
              return payload

  MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/createattachment-operation

  ### Ancestors

  - EWSAccountService
  - EWSService
  - SupportedVersionClassMixIn

  ### Class variables

  `var cls_map`

    The type of the None singleton.

  ### Methods

  `def call(self, parent_item, items)`
    Expand source code

        def call(self, parent_item, items):
            return self._elems_to_objs(self._chunked_get_elements(self.get_payload, items=items, parent_item=parent_item))

  `def get_payload(self, items, parent_item)`
    Expand source code

        def get_payload(self, items, parent_item):
            payload = create_element(f"m:{self.SERVICE_NAME}")
            version = self.account.version
            if isinstance(parent_item, BaseItem):
                # to_item_id() would convert this to a normal ItemId, but the service wants a ParentItemId
                parent_item = ParentItemId(parent_item.id, parent_item.changekey)
            set_xml_value(payload, to_item_id(parent_item, ParentItemId), version=self.account.version)
            attachments = create_element("m:Attachments")
            for item in items:
                set_xml_value(attachments, item, version=version)
            payload.append(attachments)
            return payload

  ### Inherited members

  - `EWSAccountService`:
    - `CHUNK_SIZE`
    - `ERRORS_TO_CATCH_IN_RESPONSE`
    - `NO_VALID_SERVER_VERSIONS`
    - `NS_MAP`
    - `SERVICE_NAME`
    - `WARNINGS_TO_CATCH_IN_RESPONSE`
    - `WARNINGS_TO_IGNORE_IN_RESPONSE`
    - `deprecated_from`
    - `element_container_name`
    - `get`
    - `parse`
    - `prefer_affinity`
    - `returns_elements`
    - `supported_api_versions`
    - `supported_from`
    - `wrap`