ecederstrand / exchangelib

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

OOF, The scheduled duration for sending automatic replies isn't valid #1323

Closed vepishkin closed 1 month ago

vepishkin commented 1 month ago

Hello!

Had the same problem. Discussions in this thread didn't help. I would be grateful if someone could help with the problem.

My env: Exchange 2019 Version 15.2 ‎(Build 1258.12)‎ exchangelib/5.4.2 python-requests/2.32.3

py code:

from exchangelib import Account,Credentials,OofSettings,EWSTimeZone, EWSDateTime, DELEGATE
from datetime import datetime

import logging
from exchangelib.util import PrettyXmlHandler

logging.basicConfig(level=logging.DEBUG, handlers=[PrettyXmlHandler()])

username = 'domain\\username'
password = 'pwd'  
cred = Credentials(username, password)

a = Account(primary_smtp_address= "email",
            credentials=cred, autodiscover=True,
            access_type=DELEGATE,)

tz = EWSTimeZone.localzone()
start_time = EWSDateTime(2025, 7, 22, 1, 0, tzinfo=tz)
end_time = EWSDateTime(2025, 8, 5, 23, 59, tzinfo=tz)

a.oof_settings = OofSettings(
    state=OofSettings.SCHEDULED,
    external_audience="All",
    start=start_time,
    end=end_time,
    internal_reply="Test msg",
    external_reply="Test msg"
)

print("Success!")

DEBUG LOG:

DEBUG:tzlocal:Looking up time zone info from registry
DEBUG:exchangelib.autodiscover.discovery:Waiting for autodiscover_cache lock
DEBUG:exchangelib.autodiscover.discovery:autodiscover_cache lock acquired
DEBUG:exchangelib.autodiscover.discovery:Cache hit for key ('domain.com', Credentials('domainname\\username', '********')): https://autodiscover.domain.com/autodiscover/autodiscover.svc 
DEBUG:exchangelib.services.common:Calling service GetUserSettings
DEBUG:exchangelib.services.common:Trying API version Exchange2016
DEBUG:exchangelib.protocol:Server autodiscover.domain.com: Increasing session pool size from 0 to 1
DEBUG:exchangelib.protocol:Server autodiscover.domain.com: Created session 77417
DEBUG:exchangelib.protocol:Server autodiscover.domain.com: Waiting for session
DEBUG:exchangelib.protocol:Server autodiscover.domain.com: Got session 77417
DEBUG:exchangelib.util:Session 77417 thread 142000 timeout 10: POST'ing to https://autodiscover.domain.com/autodiscover/autodiscover.svc after 0s sleep
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): autodiscover.domain.com:443
DEBUG:urllib3.connectionpool:https://autodiscover.domain.com:443 "POST /autodiscover/autodiscover.svc HTTP/11" 401 0
DEBUG:spnego._ntlm:NTLM step input: 
DEBUG:spnego._ntlm:NTLM step output: TlRMTVNTUAABAAAAN4II4gAAAAAoAAAAAAAAACgAAAAACwAAAAAADw==
DEBUG:urllib3.connectionpool:https://autodiscover.domain.com:443 "POST /autodiscover/autodiscover.svc HTTP/11" 401 0
DEBUG:spnego._ntlm:NTLM step input: TlRMTVNTUAACAAAABAAEADgAAAA1goni7/1atBQ1a0UAAAAAAAAAAJ4AngA8AAAACgBjRQAAAA9BAEQAAgAEAEEARAABABAAQwBTAE0ALQBFAFgAMAAyAAQAHABhAGQALgBjAHMAbQBlAGQAaQBjAGEALgByAHUAAwAuAEMAUwBNAC0ARQBYADAAMgAuAGEAZAAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAFABwAYQBkAC4AYwBzAG0AZQBkAGkAYwBhAC4AcgB1AAcACACMq9E7pdnaAQAAAAA=
DEBUG:spnego._ntlm:NTLM step output: TlRMTVNTUAADAAAAGAAYAFgAAAAoASgBcAAAAAQABACYAQAAFAAUAJwBAAAKAAoAsAEAABAAEAC6AQAANYKJ4gALAAAAAAAPK1DuiFWYyshcB8MIjQ73qQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN0CUqgpjYL6LswosVNf9RgBAQAAAAAAAIyr0Tul2doBf7pWylH9nx4AAAAAAgAEAEEARAABABAAQwBTAE0ALQBFAFgAMAAyAAQAHABhAGQALgBjAHMAbQBlAGQAaQBjAGEALgByAHUAAwAuAEMAUwBNAC0ARQBYADAAMgAuAGEAZAAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAFABwAYQBkAC4AYwBzAG0AZQBkAGkAYwBhAC4AcgB1AAcACACMq9E7pdnaAQoAEABgd7ZDlGRMeWSmCAQIKFVuCQA6AGgAdAB0AHAALwBhAHUAdABvAGQAaQBzAGMAbwB2AGUAcgAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAGAAQAAgAAAAAAAAAAAAAAYQBkAHYALgBlAHAAaQBzAGgAawBpAG4ATgAwADAANAAzABBYqbDMtLoIbQcZDnyvi0E=
DEBUG:urllib3.connectionpool:https://autodiscover.domain.com:443 "POST /autodiscover/autodiscover.svc HTTP/11" 200 None
DEBUG:exchangelib.util:Timeout: 10
Session: 77417
Thread: 142000
Auth type: <requests_ntlm.requests_ntlm.HttpNtlmAuth object at 0x00000192F0175250>
URL: https://autodiscover.domain.com/autodiscover/autodiscover.svc
HTTP adapter: <requests.adapters.HTTPAdapter object at 0x00000192F0174E90>
Streaming: False
Response time: 0.125
Status code: 200
Request headers: {'User-Agent': 'exchangelib/5.4.2 (python-requests/2.32.3)', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'Keep-Alive', 'Content-Type': 'text/xml; charset=utf-8', 'Content-Length': '3655', 'Authorization': 'NTLM TlRMTVNTUAADAAAAGAAYAFgAAAAoASgBcAAAAAQABACYAQAAFAAUAJwBAAAKAAoAsAEAABAAEAC6AQAANYKJ4gALAAAAAAAPK1DuiFWYyshcB8MIjQ73qQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN0CUqgpjYL6LswosVNf9RgBAQAAAAAAAIyr0Tul2doBf7pWylH9nx4AAAAAAgAEAEEARAABABAAQwBTAE0ALQBFAFgAMAAyAAQAHABhAGQALgBjAHMAbQBlAGQAaQBjAGEALgByAHUAAwAuAEMAUwBNAC0ARQBYADAAMgAuAGEAZAAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAFABwAYQBkAC4AYwBzAG0AZQBkAGkAYwBhAC4AcgB1AAcACACMq9E7pdnaAQoAEABgd7ZDlGRMeWSmCAQIKFVuCQA6AGgAdAB0AHAALwBhAHUAdABvAGQAaQBzAGMAbwB2AGUAcgAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAGAAQAAgAAAAAAAAAAAAAAYQBkAHYALgBlAHAAaQBzAGgAawBpAG4ATgAwADAANAAzABBYqbDMtLoIbQcZDnyvi0E='}
Response headers: {'cache-control': 'private', 'transfer-encoding': 'chunked', 'content-type': 'text/xml; charset=utf-8', 'content-encoding': 'gzip', 'vary': 'Accept-Encoding', 'server': 'Microsoft-IIS/10.0', 'request-id': '416a96ee-baad-405b-aabd-a94bb63dafaf', 'x-calculatedbetarget': 'ex02.ad.domain.com', 'x-diaginfo': 'ex02', 'x-beserver': 'ex02', 'x-aspnet-version': '4.0.30319', 'set-cookie': 'X-BackEndCookie=S-1-5-21-2627001870-1185970678-192068996-3379=u56Lnp2ejJqBncnIzcmanZnSzp6ZyNLLzcfL0sbJyJrSmsvIx5nIxsfGzMjLgYHNz83L0s/H0s7Hq8/JxczOxc/KgZ6b0ZyMkpqblpye0Y2Kgc8=; expires=Sun, 18-Aug-2024 06:31:05 GMT; path=/autodiscover; secure; HttpOnly', 'persistent-auth': 'true', 'x-powered-by': 'ASP.NET', 'x-feserver': 'ex02', 'date': 'Fri, 19 Jul 2024 06:31:04 GMT', 'x-frame-options': 'SAMEORIGIN', 'x-content-type-options': 'nosniff'}
DEBUG:exchangelib.util.xml:Request XML: <?xml version='1.0' encoding='utf-8'?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
    xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover"
    xmlns:wsa="http://www.w3.org/2005/08/addressing"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <s:Header>
    <a:RequestedServerVersion>Exchange2016</a:RequestedServerVersion>
    <wsa:Action>http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>
    <wsa:To>https://autodiscover.domain.com/autodiscover/autodiscover.svc</wsa:To>
  </s:Header>
  <s:Body>
    <a:GetUserSettingsRequestMessage>
      <a:Request>
        <a:Users>
          <a:User>
            <a:Mailbox>username@domain.com</a:Mailbox>
          </a:User>
        </a:Users>
        <a:RequestedSettings>
          <a:Setting>ActiveDirectoryServer</a:Setting>
          <a:Setting>AlternateMailboxes</a:Setting>
          <a:Setting>AutoDiscoverSMTPAddress</a:Setting>
          <a:Setting>CasVersion</a:Setting>
          <a:Setting>CrossOrganizationSharingEnabled</a:Setting>
          <a:Setting>EcpDeliveryReportUrlFragment</a:Setting>
          <a:Setting>EcpEmailSubscriptionsUrlFragment</a:Setting>
          <a:Setting>EcpPublishingUrlFragment</a:Setting>
          <a:Setting>EcpRetentionPolicyTagsUrlFragment</a:Setting>
          <a:Setting>EcpTextMessagingUrlFragment</a:Setting>
          <a:Setting>EcpVoicemailUrlFragment</a:Setting>
          <a:Setting>EwsSupportedSchemas</a:Setting>
          <a:Setting>ExchangeRpcUrl</a:Setting>
          <a:Setting>ExternalEcpDeliveryReportUrl</a:Setting>
          <a:Setting>ExternalEcpEmailSubscriptionsUrl</a:Setting>
          <a:Setting>ExternalEcpPublishingUrl</a:Setting>
          <a:Setting>ExternalEcpRetentionPolicyTagsUrl</a:Setting>
          <a:Setting>ExternalEcpTextMessagingUrl</a:Setting>
          <a:Setting>ExternalEcpUrl</a:Setting>
          <a:Setting>ExternalEcpVoicemailUrl</a:Setting>
          <a:Setting>ExternalEwsUrl</a:Setting>
          <a:Setting>ExternalEwsVersion</a:Setting>
          <a:Setting>ExternalImap4Connections</a:Setting>
          <a:Setting>ExternalMailboxServer</a:Setting>
          <a:Setting>ExternalMailboxServerAuthenticationMethods</a:Setting>
          <a:Setting>ExternalMailboxServerRequiresSSL</a:Setting>
          <a:Setting>ExternalOABUrl</a:Setting>
          <a:Setting>ExternalPop3Connections</a:Setting>
          <a:Setting>ExternalServerExclusiveConnect</a:Setting>
          <a:Setting>ExternalSmtpConnections</a:Setting>
          <a:Setting>ExternalUMUrl</a:Setting>
          <a:Setting>ExternalWebClientUrls</a:Setting>
          <a:Setting>GroupingInformation</a:Setting>
          <a:Setting>InternalEcpDeliveryReportUrl</a:Setting>
          <a:Setting>InternalEcpEmailSubscriptionsUrl</a:Setting>
          <a:Setting>InternalEcpPublishingUrl</a:Setting>
          <a:Setting>InternalEcpRetentionPolicyTagsUrl</a:Setting>
          <a:Setting>InternalEcpTextMessagingUrl</a:Setting>
          <a:Setting>InternalEcpUrl</a:Setting>
          <a:Setting>InternalEcpVoicemailUrl</a:Setting>
          <a:Setting>InternalEwsUrl</a:Setting>
          <a:Setting>InternalImap4Connections</a:Setting>
          <a:Setting>InternalMailboxServer</a:Setting>
          <a:Setting>InternalMailboxServerDN</a:Setting>
          <a:Setting>InternalOABUrl</a:Setting>
          <a:Setting>InternalPop3Connections</a:Setting>
          <a:Setting>InternalRpcClientServer</a:Setting>
          <a:Setting>InternalServerExclusiveConnect</a:Setting>
          <a:Setting>InternalSmtpConnections</a:Setting>
          <a:Setting>InternalUMUrl</a:Setting>
          <a:Setting>InternalWebClientUrls</a:Setting>
          <a:Setting>InteropExternalEwsUrl</a:Setting>
          <a:Setting>InteropExternalEwsVersion</a:Setting>
          <a:Setting>MailboxDN</a:Setting>
          <a:Setting>MapiHttpEnabled</a:Setting>
          <a:Setting>MobileMailboxPolicyInterop</a:Setting>
          <a:Setting>PublicFolderServer</a:Setting>
          <a:Setting>ShowGalAsDefaultView</a:Setting>
          <a:Setting>UserDeploymentId</a:Setting>
          <a:Setting>UserDisplayName</a:Setting>
          <a:Setting>UserDN</a:Setting>
          <a:Setting>UserMSOnline</a:Setting>
        </a:RequestedSettings>
      </a:Request>
    </a:GetUserSettingsRequestMessage>
  </s:Body>
</s:Envelope>
Response XML: <?xml version='1.0' encoding='utf-8'?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:a="http://www.w3.org/2005/08/addressing">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettingsResponse</a:Action>
    <h:ServerVersionInfo
    xmlns:h="http://schemas.microsoft.com/exchange/2010/Autodiscover"
    xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <h:MajorVersion>15</h:MajorVersion>
      <h:MinorVersion>2</h:MinorVersion>
      <h:MajorBuildNumber>1258</h:MajorBuildNumber>
      <h:MinorBuildNumber>34</h:MinorBuildNumber>
      <h:Version>Exchange2015</h:Version>
    </h:ServerVersionInfo>
  </s:Header>
  <s:Body>
    <GetUserSettingsResponseMessage xmlns="http://schemas.microsoft.com/exchange/2010/Autodiscover">
      <Response
    xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
EBUG:exchangelib.util:Session 77417 thread 142000: Useful response from https://autodiscover.domain.com/autodiscover/autodiscover.svc
DEBUG:exchangelib.protocol:Server autodiscover.domain.com: Releasing session 77417
DEBUG:exchangelib.version:API version "Exchange2016" worked but server reports version "Exchange2015". Using "Exchange2015"
WARNING:exchangelib.version:Full name for API version Exchange2015 build 15.2.1258.34 is unknown
DEBUG:exchangelib.services.common:Found new version (Build=15.20.0.0, API=Exchange2016, Fullname=Microsoft Exchange Server Office365 -> Build=15.2.1258.34, API=Exchange2015, Fullname=UNKNOWN)
INFO:exchangelib.autodiscover.discovery:Step 5: Checking response
DEBUG:exchangelib.autodiscover.discovery:Released autodiscover_cache_lock
DEBUG:exchangelib.protocol:Waiting for _protocol_cache_lock
DEBUG:exchangelib.protocol:Protocol __call__ cache miss. Adding key '('https://ex01.domain.com/EWS/Exchange.asmx', Credentials('domainname\\username', '********'))'
DEBUG:exchangelib.account:Added account: username@domain.com
DEBUG:exchangelib.services.common:Calling service SetUserOofSettings
DEBUG:exchangelib.services.common:Trying API version Exchange2015
DEBUG:exchangelib.protocol:Server ex01.domain.com: Increasing session pool size from 0 to 1
DEBUG:exchangelib.transport:Requesting 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="Exchange2016"/></s:Header><s:Body><m:ConvertId DestinationFormat="EntryId"><m:SourceIds><t:AlternateId Id="DUMMY" Format="EwsId" Mailbox="DUMMY"/></m:SourceIds></m:ConvertId></s:Body></s:Envelope>' from https://ex01.domain.com/EWS/Exchange.asmx
DEBUG:exchangelib.transport:Trying to get service auth type for https://ex01.domain.com/EWS/Exchange.asmx
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): ex01.domain.com:443
DEBUG:urllib3.connectionpool:https://ex01.domain.com:443 "POST /EWS/Exchange.asmx HTTP/11" 401 0
DEBUG:exchangelib.transport:Request headers: {'User-Agent': 'exchangelib/5.4.2 (python-requests/2.32.3)', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'text/xml; charset=utf-8', 'Content-Length': '481'}
DEBUG:exchangelib.transport:Response headers: {'server': 'Microsoft-IIS/10.0', 'request-id': '30bcff85-89f9-42ca-9ef6-4024654fd0df', 'x-owa-version': '15.2.1258.34', 'www-authenticate': 'Negotiate, NTLM', 'x-powered-by': 'ASP.NET', 'x-feserver': 'ex02', 'date': 'Fri, 19 Jul 2024 06:31:04 GMT', 'content-length': '0', 'x-frame-options': 'SAMEORIGIN', 'x-content-type-options': 'nosniff'}
DEBUG:exchangelib.transport:Auth type is NTLM
DEBUG:exchangelib.protocol:Server ex01.domain.com: Created session 28573
DEBUG:exchangelib.protocol:Server ex01.domain.com: Waiting for session
DEBUG:exchangelib.protocol:Server ex01.domain.com: Got session 28573
DEBUG:exchangelib.util:Session 28573 thread 142000 timeout 120: POST'ing to https://ex01.domain.com/EWS/Exchange.asmx after 0s sleep
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): ex01.domain.com:443
DEBUG:urllib3.connectionpool:https://ex01.domain.com:443 "POST /EWS/Exchange.asmx HTTP/11" 401 0
DEBUG:spnego._ntlm:NTLM step input:
DEBUG:spnego._ntlm:NTLM step output: TlRMTVNTUAABAAAAN4II4gAAAAAoAAAAAAAAACgAAAAACwAAAAAADw==
DEBUG:urllib3.connectionpool:https://ex01.domain.com:443 "POST /EWS/Exchange.asmx HTTP/11" 401 0
DEBUG:spnego._ntlm:NTLM step input: TlRMTVNTUAACAAAABAAEADgAAAA1goniVSmjGOtwvBUAAAAAAAAAAJ4AngA8AAAACgBjRQAAAA9BAEQAAgAEAEEARAABABAAQwBTAE0ALQBFAFgAMAAyAAQAHABhAGQALgBjAHMAbQBlAGQAaQBjAGEALgByAHUAAwAuAEMAUwBNAC0ARQBYADAAMgAuAGEAZAAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAFABwAYQBkAC4AYwBzAG0AZQBkAGkAYwBhAC4AcgB1AAcACABldvQ7pdnaAQAAAAA=
DEBUG:spnego._ntlm:NTLM step output: TlRMTVNTUAADAAAAGAAYAFgAAAAcARwBcAAAAAQABACMAQAAFAAUAJABAAAKAAoApAEAABAAEACuAQAANYKJ4gALAAAAAAAPEozjQK63qO5hORKPmJmkVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJb6a3B6eUXL1esVhxlfAaoBAQAAAAAAAGV29Dul2doBG2C2ApJB/QgAAAAAAgAEAEEARAABABAAQwBTAE0ALQBFAFgAMAAyAAQAHABhAGQALgBjAHMAbQBlAGQAaQBjAGEALgByAHUAAwAuAEMAUwBNAC0ARQBYADAAMgAuAGEAZAAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAFABwAYQBkAC4AYwBzAG0AZQBkAGkAYwBhAC4AcgB1AAcACABldvQ7pdnaAQoAEABgd7ZDlGRMeWSmCAQIKFVuCQAuAGgAdAB0AHAALwBtAGEAaQBsADAAMQAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAGAAQAAgAAAAAAAAAAAAAAYQBkAHYALgBlAHAAaQBzAGgAawBpAG4ATgAwADAANAAzABNOILyL7Ds2l9g0uoE+XNo=
DEBUG:urllib3.connectionpool:https://ex01.domain.com:443 "POST /EWS/Exchange.asmx HTTP/11" 200 None
DEBUG:exchangelib.util:Timeout: 120
Session: 28573
Thread: 142000
Auth type: <requests_ntlm.requests_ntlm.HttpNtlmAuth object at 0x00000192F0255E90>
URL: https://ex01.domain.com/EWS/Exchange.asmx
HTTP adapter: <requests.adapters.HTTPAdapter object at 0x00000192F023EED0>
Streaming: False
Response time: 0.09399999992456287
Status code: 200
Request headers: {'User-Agent': 'exchangelib/5.4.2 (python-requests/2.32.3)', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'Keep-Alive', 'Content-Type': 'text/xml; charset=utf-8', 'X-AnchorMailbox': 'username@domain.com', 'Content-Length': '1004', 'Authorization': 'NTLM TlRMTVNTUAADAAAAGAAYAFgAAAAcARwBcAAAAAQABACMAQAAFAAUAJABAAAKAAoApAEAABAAEACuAQAANYKJ4gALAAAAAAAPEozjQK63qO5hORKPmJmkVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJb6a3B6eUXL1esVhxlfAaoBAQAAAAAAAGV29Dul2doBG2C2ApJB/QgAAAAAAgAEAEEARAABABAAQwBTAE0ALQBFAFgAMAAyAAQAHABhAGQALgBjAHMAbQBlAGQAaQBjAGEALgByAHUAAwAuAEMAUwBNAC0ARQBYADAAMgAuAGEAZAAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAFABwAYQBkAC4AYwBzAG0AZQBkAGkAYwBhAC4AcgB1AAcACABldvQ7pdnaAQoAEABgd7ZDlGRMeWSmCAQIKFVuCQAuAGgAdAB0AHAALwBtAGEAaQBsADAAMQAuAGMAcwBtAGUAZABpAGMAYQAuAHIAdQAGAAQAAgAAAAAAAAAAAAAAYQBkAHYALgBlAHAAaQBzAGgAawBpAG4ATgAwADAANAAzABNOILyL7Ds2l9g0uoE+XNo='}
Response headers: {'cache-control': 'private', 'transfer-encoding': 'chunked', 'content-type': 'text/xml; charset=utf-8', 'content-encoding': 'gzip', 'vary': 'Accept-Encoding', 'server': 'Microsoft-IIS/10.0', 'request-id': '61452e4a-62ab-4b9b-be33-a2b794067823', 'x-calculatedbetarget': 'ex02.ad.domain.com', 'x-diaginfo': 'ex02', 'x-beserver': 'ex02', 'x-aspnet-version': '4.0.30319', 'set-cookie': 'exchangecookie=f7fc3fefc9b184wecdeb73198ab5f2387eee7; expires=Sat, 19-Jul-2025 06:31:05 GMT; path=/; HttpOnly, X-BackEndCookie=username@domain.com=u56Lnp2ejJqBndcnI2zcmanZnSzp6DZyNLLzcfL0sbJyJrSmsv11Ix5nIxsfGzMjLgYHNzf83L0s/H0s7Hq8/JxczOxc/KgZ6b0ZyMkpqblpye0Y2Kgc8=; expires=Sun, 18-Aug-2024 06:31:05 GMT; path=/EWS; secure; HttpOnly', 'persistent-auth': 'true', 'x-powered-by': 'ASP.NET', 'x-feserver': 'ex02', 'date': 'Fri, 19 Jul 2024 06:31:05 GMT', 'x-frame-options': 'SAMEORIGIN', 'x-content-type-options': 'nosniff'}
DEBUG:exchangelib.util.xml:Request XML: <?xml version='1.0' encoding='utf-8'?>
<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="Exchange2015"/>
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="Russian Standard Time"/>
    </t:TimeZoneContext>
  </s:Header>
  <s:Body>
    <m:SetUserOofSettingsRequest>
      <t:Mailbox>
        <t:Address>username@domain.com</t:Address>
        <t:RoutingType>SMTP</t:RoutingType>
      </t:Mailbox>
      <t:UserOofSettings>
        <t:OofState>Scheduled</t:OofState>
        <t:ExternalAudience>All</t:ExternalAudience>
        <t:Duration>
          <t:StartTime>2025-07-22T01:00:00+03:00</t:StartTime>
          <t:EndTime>2025-08-05T23:59:00+03:00</t:EndTime>
        </t:Duration>
        <t:InternalReply>
          <t:Message>Test msg</t:Message>
        </t:InternalReply>
        <t:ExternalReply>
          <t:Message>Test msg</t:Message>
        </t:ExternalReply>
      </t:UserOofSettings>
    </m:SetUserOofSettingsRequest>
  </s:Body>
</s:Envelope>
Response XML: <?xml version='1.0' encoding='utf-8'?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo
    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" MajorVersion="15" MinorVersion="2" MajorBuildNumber="1258" MinorBuildNumber="34" Version="V2017_07_11"/>
  </s:Header>
  <s:Body
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SetUserOofSettingsResponse xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <ResponseMessage ResponseClass="Error">
        <MessageText>Microsoft.Exchange.InfoWorker.Common.OOF.InvalidScheduledOofDuration: The scheduled duration for sending automatic replies isn't valid.&#13;
   at Microsoft.Exchange.InfoWorker.Common.OOF.UserOofSettings.ValidateDuration(Duration duration)&#13;
   at Microsoft.Exchange.InfoWorker.Common.OOF.UserOofSettings.Validate(MailboxSession itemStore, UserOofSettings userOofSettings)&#13;
   at Microsoft.Exchange.InfoWorker.Common.OOF.UserOofSettings.Save(MailboxSession itemStore, Boolean skipAntispamCheck)&#13;
   at Microsoft.Exchange.Services.Core.SetUserOofSettings.SetUserOofSettingsExecute()</MessageText>
        <ResponseCode>ErrorInvalidScheduledOofDuration</ResponseCode>
        <DescriptiveLinkKey>0</DescriptiveLinkKey>
        <MessageXml>
          <ExceptionType xmlns="http://schemas.microsoft.com/exchange/services/2006/errors">InvalidScheduledOofDuration</ExceptionType>
          <ExceptionCode xmlns="http://schemas.microsoft.com/exchange/services/2006/errors">225</ExceptionCode>
          <ExceptionMessage xmlns="http://schemas.microsoft.com/exchange/services/2006/errors">The scheduled duration for sending automatic replies isn't valid.</ExceptionMessage>   
        </MessageXml>
      </ResponseMessage>
    </SetUserOofSettingsResponse>
  </s:Body>
</s:Envelope>
DEBUG:exchangelib.util:Session 28573 thread 142000: Useful response from https://ex01.domain.com/EWS/Exchange.asmx
DEBUG:exchangelib.protocol:Server ex01.domain.com: Releasing session 28573
DEBUG:exchangelib.version:API version "Exchange2015" worked but server reports version "V2017_07_11". Using "Exchange2015"
WARNING:exchangelib.version:Full name for API version Exchange2015 build 15.2.1258.34 is unknown
DEBUG:exchangelib.services.common:Found new version (Build=15.20.0.0, API=Exchange2015, Fullname=Microsoft Exchange Server 2015 -> Build=15.2.1258.34, API=Exchange2015, Fullname=UNKNOWN)
ecederstrand commented 1 month ago

It’s an internal Exchange error message with no additional information on why the duration is invalid. I would suggest either:

ecederstrand commented 1 month ago

I'll close the issue until we have some indication that we can help users with a better error message, or detect this situation up-front in exchangelib. As it stands, I don't think we can do any better than display the error message from the server.

vepishkin commented 1 month ago

@ecederstrand Sorry for a long answer, i was away. The MS website indicates in the example a format like this:

 <Duration>
          <StartTime>2005-10-05T00:00:00</StartTime>
          <EndTime>2005-10-25T00:00:00</EndTime>
 </Duration>

YYYY-MM-DD HH:MM:SS (time zone is not transmitted)

but the script sends it in a different format, maybe that's the problem?

<t:Duration>
          <t:StartTime>2025-07-22T01:00:00+03:00</t:StartTime>
          <t:EndTime>2025-08-05T23:59:00+03:00</t:EndTime>
</t:Duration>

YYYY-MM-DD HH:MM:SS+UTC

ecederstrand commented 4 weeks ago

Setting the duration works and is part of the test suite, so it's not a general problem with the datetime format.