ecederstrand / exchangelib

Python client for Microsoft Exchange Web Services (EWS)
BSD 2-Clause "Simplified" License
1.18k stars 248 forks source link

CalendarItem: Updating required attendees triggers email to all #746

Closed MHC2000 closed 4 years ago

MHC2000 commented 4 years ago

Hello,

I have difficulties zu update an existing CalendarItem. When I change the required attendees and nothing else and also choose SEND_TO_CHANGED_AND_SAVE_COPY exchange sends the calendar update to everyone and not only to the removed or added users. What am I doing wrong? Test code:

...
ews_connection = Account(primary_smtp_address='admin@test.com', config=config, autodiscover=False, access_type=DELEGATE)
calendar_item = ews_connection.calendar.get(id=search_event_item_id)
calendar_item.required_attendees = ['address1@test.com', 'address2@test.com']
calendar_item.save(update_fields=['required_attendees'], send_meeting_invitations=SEND_TO_CHANGED_AND_SAVE_COPY)

calendar_item.required_attendees = ['address1@test.com', 'address3@test.com']
calendar_item.save(update_fields=['required_attendees'], send_meeting_invitations=SEND_TO_CHANGED_AND_SAVE_COPY)

The email address1@test.com is triggered all the time and gets an update for the calendar entry. Am I wrong to choose SEND_TO_CHANGED_AND_SAVE_COPY? As far as I understand EWS it shouldn't trigger address1 to send an update?

Does anyone have an idea what I'm doing wrong or is this a bug? Thanks for the help?

Regards,

ecederstrand commented 4 years ago

That's my understanding as well, but EWS may have a different definition of who is affected by a change like this. See the docs at https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/updateitem#sendmeetinginvitationsorcancellations-attribute

You could enable debug logging to check that your enum value is in fact present in the requests exchangelib is sending to the server. See https://github.com/ecederstrand/exchangelib#troubleshooting

MHC2000 commented 4 years ago

Thanks for the fast response and documents.

How can I query the enum values for SendMeetingInvitationsOrCancellations at our server?

When I look into the response I don't see anything which suggests, that there is something wrong (xxxx is added from myside). The only thing I see is the ConflictResultsCount is 1, but no further information on this. The server is running on Exchange2019, but the API-Version is Exchange2013_SP1

Retry: 0 Waited: 10 Timeout: 120 Session: 24374 Thread: 39276 Auth type: <requests_ntlm.requests_ntlm.HttpNtlmAuth object at 0x0000015D9EDB4348> URL: https://XXXXX/EWS/Exchange.asmx HTTP adapter: <requests.adapters.HTTPAdapter object at 0x0000015D9EE6BAC8> Allow redirects: False Streaming: False Response time: 0.13999999999941792 Status code: 200 Request headers: {'User-Agent': 'exchangelib/3.1.1 (python-requests/2.23.0)', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'Keep-Alive', 'Content-Type': 'text/xml; charset=utf-8', 'X-AnchorMailbox': 'XXXXX', 'Cookie': 'X-BackEndCookie=S-1-5-21-43206524-2104247658-1151357142-3317555=u56Lnp2ejJqByMbIm8aem8/Sm8nPyNLLnsab0p7OnsvSycbNm8bLy5zHxpuagYHNz83P0s/K0s3Lq8/IxcvMxc7G&XXXXX=u56Lnp2ejJqByMbIm8aem8/Sm8nPyNLLnsab0p7OnsvSycbNm8bLy5zHxpuagYHNz83P0s/K0s3Lq8/IxcvMxc3M; ClientId=KQMHWDEKX0ECUUDLATNRW; exchangecookie=347fd2b5adf84c7d868427df69a4e090', 'Content-Length': '1304'} Response headers: {'Cache-Control': 'private', 'Transfer-Encoding': 'chunked', 'Content-Type': 'text/xml; charset=utf-8', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'Server': 'Microsoft-IIS/8.5', 'request-id': '0c36b3a1-a4dd-4dfe-8aa6-8a91ed4dd6f6', 'X-CalculatedBETarget': 'XXXXX', 'X-DiagInfo': 'XXXXX', 'X-BEServer': 'XXXXX', 'X-AspNet-Version': '4.0.30319', 'Set-Cookie': 'exchangecookie=347fd2b5adf84c7d868427df69a4e090; path=/, X-BackEndCookie=S-1-5-21-43206524-2104247658-1151357142-3317555=u56Lnp2ejJqByMbIm8aem8/Sm8nPyNLLnsab0p7OnsvSycbNm8bLy5zHxpuagYHNz83P0s/K0s3Lq8/IxcvMxc7G&XXXXX=u56Lnp2ejJqByMbIm8aem8/Sm8nPyNLLnsab0p7OnsvSycbNm8bLy5zHxpuagYHNz83P0s/K0s3Lq8/IxcvMxc3L; expires=Sun, 24-May-2020 07:43:24 GMT; path=/EWS; secure; HttpOnly; SameSite=None', 'X-Powered-By': 'ASP.NET', 'X-FEServer': 'XXXXX', 'Date': 'Fri, 24 Apr 2020 07:43:23 GMT'} Request data: b'<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><s:Header><t:RequestServerVersion Version="Exchange2013_SP1"/><t:TimeZoneContext><t:TimeZoneDefinition Id="W. Europe Standard Time"/></t:TimeZoneContext></s:Header><s:Body><m:UpdateItem ConflictResolution="AutoResolve" MessageDisposition="SaveOnly" SendMeetingInvitationsOrCancellations="SendToChangedAndSaveCopy" SuppressReadReceipts="true"><m:ItemChanges><t:ItemChange><t:ItemId Id="AAMkAGQwNTgwNjYzLTRkZWEtNDNjZi1iYTE0LWY2Nzk3YWQxOTAzMgBGAAAAAABybNxsMJTUTpHqs6ZiExgXBwAYsi5e5XbBTryuwB6tgfCRAAAAAAENAAAYsi5e5XbBTryuwB6tgfCRAAHv+B8BAAA=" ChangeKey="DwAAABYAAAAYsi5e5XbBTryuwB6tgfCRAAHwCS95"/><t:Updates><t:SetItemField><t:FieldURI FieldURI="calendar:RequiredAttendees"/><t:CalendarItem><t:RequiredAttendees><t:Attendee><t:Mailbox><t:EmailAddress>XXXXX</t:EmailAddress><t:RoutingType>SMTP</t:RoutingType><t:MailboxType>Mailbox</t:MailboxType></t:Mailbox><t:ResponseType>Accept</t:ResponseType></t:Attendee></t:RequiredAttendees></t:CalendarItem></t:SetItemField></t:Updates></t:ItemChange></m:ItemChanges></m:UpdateItem></s:Body></s:Envelope>' Response data: b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="1473" MinorBuildNumber="5" Version="V2_23" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><m:UpdateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><m:ResponseMessages><m:UpdateItemResponseMessage ResponseClass="Success"><m:ResponseCode>NoError</m:ResponseCode><m:Items><t:CalendarItem><t:ItemId Id="AAMkAGQwNTgwNjYzLTRkZWEtNDNjZi1iYTE0LWY2Nzk3YWQxOTAzMgBGAAAAAABybNxsMJTUTpHqs6ZiExgXBwAYsi5e5XbBTryuwB6tgfCRAAAAAAENAAAYsi5e5XbBTryuwB6tgfCRAAHv+B8BAAA=" ChangeKey="DwAAABYAAAAYsi5e5XbBTryuwB6tgfCRAAHwCS97"/></t:CalendarItem></m:Items><m:ConflictResults><t:Count>1</t:Count></m:ConflictResults></m:UpdateItemResponseMessage></m:ResponseMessages></m:UpdateItemResponse></s:Body></s:Envelope>'

ecederstrand commented 4 years ago

Your request contains <m:UpdateItem ConflictResolution="AutoResolve" MessageDisposition="SaveOnly" SendMeetingInvitationsOrCancellations="SendToChangedAndSaveCopy" SuppressReadReceipts="true"> which looks correct.

https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/updateitem#sendmeetinginvitationsorcancellations-attribute lists the enum values that EWS supports for all these XML attributes.

At this point, I think the conclusion is that this is just how EWS works.

MHC2000 commented 4 years ago

At this point, I think the conclusion is that this is just how EWS works.

Sad but true. But thanks a lot for the help!