通过 EWS 延迟发送电子邮件会在未实际发送邮件的情况下将邮件留在已发送项目中

Delay sending an email via EWS leaves mail in sent-items without actually sending it

我正在尝试从 Word VBA 模块通过 EWS (Exchange 2019) 延迟发送电子邮件。这很好用,只要我立即发送。只要我添加延迟发送的元素

<t:ExtendedProperty>
  <t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime" />
  <t:Value>2022-01-01T00:00:00.000</t:Value>
</t:ExtendedProperty>

邮件立即进入已发送项目,但未送达。这是完整的代码——为了更好的可读性,下面的 XML:

Private Sub SendEMail()
  Dim sReq As String
  Dim xmlMethod As String
  Dim XMLreq As New MSXML2.XMLHTTP60
  Dim EWSEndPoint As String
  
  Dim t As String
  t = "2022-01-01T00:00:00.000"
  
  EWSEndPoint = "https://myexchange/EWS/Exchange.asmx"
  sReq = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf & _
          "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:t=""http://schemas.microsoft.com/exchange/services/2006/types"">" & vbCrLf & _
            "<soap:Header>" & vbCrLf & "<t:RequestServerVersion Version=""Exchange2016""/>" & vbCrLf & "</soap:Header>" & vbCrLf & _
            "<soap:Body>" & vbCrLf & _
              "<CreateItem MessageDisposition=""SendAndSaveCopy"" xmlns=""http://schemas.microsoft.com/exchange/services/2006/messages"">" & vbCrLf & _
                "<SavedItemFolderId>" & vbCrLf & _
                  "<t:DistinguishedFolderId Id=""sentitems"" />" & vbCrLf & _
                "</SavedItemFolderId>" & vbCrLf & _
                "<Items>" & vbCrLf & _
                  "<t:Message>" & vbCrLf & _
                    "<t:ItemClass>IPM.Note</t:ItemClass>" & vbCrLf & _
                    "<t:Subject>" & "123 " & Now() & " für " & t & "</t:Subject>" & vbCrLf & _
                    "<t:Body BodyType=""Text"">" & "body" & "</t:Body>" & vbCrLf & _
                    "<t:ExtendedProperty>" & vbCrLf & _
                      "<t:ExtendedFieldURI PropertyTag=""16367"" PropertyType=""SystemTime"" />" & vbCrLf & _
                      "<t:Value>" & t & "</t:Value>" & vbCrLf & _
                    "</t:ExtendedProperty>" & vbCrLf & _
                    "<t:ToRecipients>" & vbCrLf & _
                      "<t:Mailbox>" & vbCrLf & "<t:EmailAddress>" & "myemail" & "</t:EmailAddress>" & vbCrLf & "</t:Mailbox>" & vbCrLf & _
                    "</t:ToRecipients>" & vbCrLf & _
                  "</t:Message>" & vbCrLf & _
                "</Items>" & vbCrLf & _
              "</CreateItem>" & vbCrLf & _
            "</soap:Body>" & vbCrLf & _
          "</soap:Envelope>" & vbCrLf

  xmlMethod = "POST"
  XMLreq.Open xmlMethod, EWSEndPoint, False, "myusername", "mypassword"
  XMLreq.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
  XMLreq.Send sReq

  If XMLreq.Status = 200 Then
                    ' Message Sent okay
                    MsgBox ("ok")
  Else
                    ' Something went Wrong
                    MsgBox ("error")
  End If
End Sub

这里是 XML:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2016"/>
</soap:Header>
<soap:Body>
<CreateItem MessageDisposition="SendAndSaveCopy" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<SavedItemFolderId>
<t:DistinguishedFolderId Id="sentitems" />
</SavedItemFolderId>
<Items>
<t:Message>
<t:ItemClass>IPM.Note</t:ItemClass>
<t:Subject>123 31.03.2021 13:35:19 für 2022-01-01T00:00:00.000</t:Subject>
<t:Body BodyType="Text">body</t:Body>
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime" />
<t:Value>2022-01-01T00:00:00.000</t:Value>
</t:ExtendedProperty>
<t:ToRecipients>
<t:Mailbox>
<t:EmailAddress>myemail</t:EmailAddress>
</t:Mailbox>
</t:ToRecipients>
</t:Message>
</Items>
</CreateItem>
</soap:Body>
</soap:Envelope>

我在欧洲,所以是 24 小时制。为了避免时间和日期格式的混乱,我在示例中使用了简单的一天,但这没有任何区别。我试过过去和未来的日期,没有变化:邮件会立即转到已发送的项目,但不会发送。 (xmlreq.send 行总是在没有错误的情况下关闭。)一旦我删除了四个扩展属性行,它就会毫无问题地发送。

我忽略了什么?

删除 SavedFolderId 它无论如何都是可选的但是当我用它测试你的 XML 时我看到同样的问题所以

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2016"/>
</soap:Header>
<soap:Body>
<CreateItem MessageDisposition="SendAndSaveCopy" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<Items>
<t:Message>
<t:ItemClass>IPM.Note</t:ItemClass>
<t:Subject>123 31.03.2021 13:35:19 für 2022-01-01T00:00:00.000</t:Subject>
<t:Body BodyType="Text">body</t:Body>
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime" />
<t:Value>2021-03-31T23:06:00.000</t:Value>
</t:ExtendedProperty>
<t:ToRecipients>
<t:Mailbox>
<t:EmailAddress>glenscales@yahoo.com</t:EmailAddress>
</t:Mailbox>
</t:ToRecipients>
</t:Message>
</Items>
</CreateItem>
</soap:Body>
</soap:Envelope>

对我来说没问题,它会将邮件临时保存到草稿文件夹(而不是发件箱),但一旦发送,邮件最终会进入 SentItems 文件夹。