0

I need to build an application which simply forwards emails after reading the body (and attachments) from an exchange server. The application is built in the cloud and coded in python, so we thought we would use exchangelib.

My goal is to forward emails minimizing the egress traffic because of the cloud architecture.

From the exchangelib source code (from line 778 on) I find the following code:

    def create_forward(self, subject, body, to_recipients, cc_recipients=None, bcc_recipients=None):
        if not self.account:
            raise ValueError('%s must have an account' % self.__class__.__name__)
        if not self.id:
            raise ValueError('%s must have an ID' % self.__class__.__name__)
        return ForwardItem(
            account=self.account,
            reference_item_id=ReferenceItemId(id=self.id, changekey=self.changekey),
            subject=subject,
            new_body=body,
            to_recipients=to_recipients,
            cc_recipients=cc_recipients,
            bcc_recipients=bcc_recipients,
        )

    def forward(self, subject, body, to_recipients, cc_recipients=None, bcc_recipients=None):
        self.create_forward(
            subject,
            body,
            to_recipients,
            cc_recipients,
            bcc_recipients,
        ).send()

I expect that when I call forward using the email message (previously downloaded) as self, the forwarded message takes the payload from the server and not from the caller.

Hope my question is clear...

Thanks in advance

Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63
lordcenzin
  • 339
  • 3
  • 15

1 Answers1

1

The EWS ForwardItem service does not allow referencing server-side item content. You can only send forwarded content via the HTTP request.

Attachments have their own ID, so you may be able to attach the original attachment to the forward item.

Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63
  • I am not sure I correctly understood. you want to forward an existing email with attachments, so does it mean you have to ingest it in your application and then create a NEW email with the whole payload and send it? This means the email load exits from the app. Is it correct? – lordcenzin Sep 17 '19 at 11:52
  • Ah, sorry. The `ReferenceItemId` only needs the ID and changekey of the forwarded item. The attachments stay on the original item. You only have to provide the new subject and extra body to the `ForwardItem`. – Erik Cederstrand Sep 18 '19 at 06:19