beorereleverion / go-ews

golang library for interacion with EWS XML
MIT License
10 stars 6 forks source link

Unable to createItem with the given example #11

Open bleizg opened 10 months ago

bleizg commented 10 months ago

Hello,

First of all, I'm not a very advanced Golang developper. Sorry in advance if the issue is my fault.

I tried to create a new item via the createItem, but I'm getting the following exception: At least one recipient isn't valid., A message can't be sent because it contains no recipients.

After a lot of different tests, I've finally decided to test your example file against my Exchange server. The DUMP looks like this:

<?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" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
    <soap:Body>
        <m:CreateItem MessageDisposition="SendAndSaveCopy">
            <m:Items>
                <t:Message>
                    <t:Body BodyType="Text">Priority - Update specification</t:Body>
                    <t:IsRead>false</t:IsRead>
                    <t:ItemClass>IPM.Note</t:ItemClass>
                    <t:Subject>Project Action</t:Subject>
                    <ToRecipients>
                        <Mailbox>
                            <EmailAddress>sschmidt@example.com</EmailAddress>
                        </Mailbox>
                    </ToRecipients>
                </t:Message>
            </m:Items>
            <m:SavedItemFolderId>
                <t:DistinguishedFolderId Id="drafts"/>
            </m:SavedItemFolderId>
        </m:CreateItem>
    </soap:Body>
</soap:Envelope>

See how the ToRecipients is wrong. It should be <t:ToRecipients> right? The same for the childs.

I guess the Exchange server does not recognize the recipients because of this incorrect xml formatting.

What do you think?

bleizg commented 10 months ago

As a workaround, we can specify the XMLName property

    ToRecipients: []*elements.ToRecipients{
        {
            Mailbox: &elements.Mailbox{
                EmailAddress: &elements.EmailAddressNonEmptyStringType{
                    TEXT:    "sschmidt@example.com",
                    XMLName: xml.Name{Local: "t:EmailAddress"},
                },
                XMLName: xml.Name{Local: "t:Mailbox"},
            },
            XMLName: xml.Name{Local: "t:ToRecipients"},
        },
    },