Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

has invalid child element 'Attachments' in namespace #122

Open
jorgefo opened this issue Jun 16, 2020 · 2 comments
Open

has invalid child element 'Attachments' in namespace #122

jorgefo opened this issue Jun 16, 2020 · 2 comments

Comments

@jorgefo
Copy link

jorgefo commented Jun 16, 2020

Hi

I have this error when try to send email with attachments

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <s:Fault>
         <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorSchemaValidation</faultcode>
         <faultstring xml:lang="es-CL">The request failed schema validation: The element \'Message\' in namespace \'http://schemas.microsoft.com/exchange/services/2006/types\' has invalid child element \'Attachments\' in namespace \'http://schemas.microsoft.com/exchange/services/2006/types\'.</faultstring>
         <detail>
            <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorSchemaValidation</e:ResponseCode>
            <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The request failed schema validation.</e:Message>
            <t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
               <t:LineNumber>1</t:LineNumber>
               <t:LinePosition>1283</t:LinePosition>
               <t:Violation>The element \'Message\' in namespace \'http://schemas.microsoft.com/exchange/services/2006/types\' has invalid child element \'Attachments\' in namespace \'http://schemas.microsoft.com/exchange/services/2006/types\'.</t:Violation>
            </t:MessageXml>
         </detail>
      </s:Fault>
   </s:Body>
</s:Envelope>

xml send

<?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:tns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:wsi="http://ws-i.org/schemas/conformanceClaim/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Header />
   <soap:Body>
      <CreateItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" MessageDisposition="SendAndSaveCopy">
         <SavedItemFolderId>
            <t:DistinguishedFolderId Id="sentitems" />
         </SavedItemFolderId>
         <Items>
            <t:Message>
               <t:ItemClass>IPM.Note</t:ItemClass>
               <t:Subject>Test EWS Email</t:Subject>
               <t:Body BodyType="HTML">This is a test email &lt;b&gt;demo&lt;/b&gt;</t:Body>
               <t:ToRecipients>
                  <t:Mailbox>
                     <t:EmailAddress>[email protected]</t:EmailAddress>
                  </t:Mailbox>
               </t:ToRecipients>
               <t:CcRecipients>
                  <t:Mailbox>
                     <t:EmailAddress>[email protected]</t:EmailAddress>
                  </t:Mailbox>
               </t:CcRecipients>
               <t:IsRead>false</t:IsRead>
               <t:ReplyTo>
                  <t:Mailbox>
                     <t:EmailAddress>[email protected]</t:EmailAddress>
                  </t:Mailbox>
               </t:ReplyTo>
               <t:Attachments>
                  <t:FileAttachment>
                     <t:Name>firstAttachment.txt</t:Name>
                     <t:ContentType>text/plain</t:ContentType>
                     <t:Content>VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4=</t:Content>
                  </t:FileAttachment>
               </t:Attachments>
            </t:Message>
         </Items>
      </CreateItem>
   </soap:Body>
</soap:Envelope>

and this is the code

const EWS = require('node-ews');
// exchange server connection info
const ewsConfig = {
  username: 'user',
  password: 'pass',
  host: 'https://ewsdomain.com'
};
 
// initialize node-ews
const ews = new EWS(ewsConfig);
 
// define ews api function
const ewsFunction = 'CreateItem';
 
// define ews api function args
const ewsArgs = {
  "attributes" : {
    "MessageDisposition" : "SendAndSaveCopy"
  },
  "SavedItemFolderId": {
    "DistinguishedFolderId": {
      "attributes": {
        "Id": "sentitems"
      }
    }
  },
  "Items" : {
    "Message" : {
      "ItemClass": "IPM.Note",
      "Subject" : "Test EWS Email",
      "Body" : {
        "attributes": {
          "BodyType" : "HTML"
        },
        "$value": "This is a test email <b>demo</b>"
      },
      "ToRecipients" : {
        "Mailbox" : {
          "EmailAddress" : "[email protected]"
        }
      },
      "CcRecipients" : {
        "Mailbox" : {
          "EmailAddress" : "[email protected]"
        }
      },
	  "IsRead": "false",
      "ReplyTo" : {
        "Mailbox" : {
          "EmailAddress" : "[email protected]"
        }
      },
      "Attachments" : {
        "FileAttachment" : [{
          "Name" : "firstAttachment.txt",
          "ContentType" : "text/plain",
          "Content" : "VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4=",
        }]
      },
    }
  }
};
 
// query ews, print resulting JSON to console
ews.run(ewsFunction, ewsArgs)
  .then(result => {
    console.log(JSON.stringify(result));
  })
  .catch(err => {
    console.log(err);
  });
@nmarus
Copy link
Owner

nmarus commented Jun 17, 2020

@jorgefo
Copy link
Author

jorgefo commented Jun 17, 2020

Thanks for the answer

but i change this

"Attachments" : {
        "FileAttachment" : [{
          "Name" : "firstAttachment.txt",
          "ContentType" : "text/plain",
          "Content" : "VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4=",
        }]
      },

with this but the problem is the same


      "Attachments" : [{
        "FileAttachment" : [{
          "Name" : "firstAttachment.txt",
          "ContentType" : "text/plain",
          "Content" : "VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4=",
        }]
      }],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants