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
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.