@devil1313

Ошибка «The scheduled duration for sending automatic replies isn't valid» при создания автоответа через EWS Exchange на python, в чем причина?

Не получается создать запланированный автоответ на определенные даты на Exchange 2019 используя EWS и скрипт на питоне с библиотекой exchangelib . Обычный автоответ(перманентный) создается корректно. В чем могут быть причины, куда копать?

Дано:
Exchange 2019 Version 15.2 ‎(Build 1258.12)‎. Win 2019 EN. Format: Russian, for non-unicode: Russian.
exchangelib/5.4.2
python-requests/2.32.3

тестовый код на питоне для создания автответа на Exchange EWS:

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!")


в запросе передаются даты и время:
<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>


Полный вывод лога:
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>
  • Вопрос задан
  • 53 просмотра
Решения вопроса 1
@devil1313 Автор вопроса
С exchangelib не удалось решить проблему с датами и временем. Пришлось переписать на powershell. Всем спасибо за участие в решение вопроса!
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы