Reputation: 125
I'm trying to delay-send an email through EWS (Exchange 2019) from a Word VBA module. This works fine, as long as I send immediately. As soon as I add the element for delayed send
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime" />
<t:Value>2022-01-01T00:00:00.000</t:Value>
</t:ExtendedProperty>
The mail goes into sent items immediately and does not get delivered. This is the entire code - the XML is below for better readability:
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
And here's the 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>
I am in Europe here, so 24-hour-timeformat. To avoid any hazzle with time and date formatting, I have taken a simple day in the example, but that did not make any difference. I've tried past and future dates, no change: The mail goes to sent items immediately and does not send. (The xmlreq.send-lines always closes without error.) As soon as I remove the four extendedproperty-lines, it sends without problems.
What is it that I'm overlooking?
Upvotes: 1
Views: 210
Reputation: 22032
Remove the SavedFolderId it's optional anyway but when i test your XML with it I see the same problem so
<?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>[email protected]</t:EmailAddress>
</t:Mailbox>
</t:ToRecipients>
</t:Message>
</Items>
</CreateItem>
</soap:Body>
</soap:Envelope>
works okay for me, It does save the message temporary to the drafts folder (instead of the outbox) but once sent the message does end up in the SentItems Folder.
Upvotes: 1