如何使用Node-ews集成Exchange 2010版本的投票选项?

时间:2018-11-10 22:05:59

标签: javascript node.js soap exchangewebservices

我无法在发送电子邮件时创建投票选项,通过ExtendedProperty尽了最大努力,但运气不好。我是Node js的入门者,任何帮助/建议/指导都是可取的。

    const EWS = require('node-ews');
const NTLMAuth = require('httpntlm').ntlm;
const passwordPlainText = 'ABCDFGH';

// store the ntHashedPassword and lmHashedPassword to reuse later for reconnecting
const ntHashedPassword = NTLMAuth.create_NT_hashed_password(passwordPlainText);
const lmHashedPassword = NTLMAuth.create_LM_hashed_password(passwordPlainText);

// exchange server connection info
const ewsConfig = {
username: 'kiranraj.@demo.com',
nt_password: ntHashedPassword,
lm_password: lmHashedPassword,
host: 'https://mail.yyy.xxxx.com/'
};

// initialize node-ews
const ews = new EWS(ewsConfig);

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"
},
"ExtendedProperty" : {
"ExtendedFieldURI" : {
"attributes" : {
"DistinguishedPropertySetId" : "InternetHeaders",
//"PropertySetId" : "00062008-0000-0000-C000-000000000046",
//"PropertyTag" : "0x8520",
"PropertyName" : "0x8520",
//"PropertyId" : "",
"PropertyType" : "String"
}
}
,"Value" : "Omg!appeared"
},
"ToRecipients" : {
"Mailbox" : [
//{ "EmailAddress" : "kiranraj.p@demo.com" }
{ "EmailAddress" : "lokendranath.v@demo.com" }
]
},
"IsRead": "false"
}
}
};

// define custom soap header
const ewsSoapHeader = {
't:RequestServerVersion': {
attributes: {
Version: "Exchange2010"
}
}
};

// query ews, print resulting JSON to console
ews.run(ewsFunction, ewsArgs, ewsSoapHeader)
.then(result => {
console.log(JSON.stringify(result));
console.log(JSON.stringify(ewsArgs))
})
.catch(err => {
console.log(err.stack);
});

console.log(ews)   

基于上面的代码,我能够发送邮件,但在已发送的邮件中看不到“投票选项”。

{"ResponseMessages":{"CreateItemResponseMessage":{"attributes":{"ResponseClass":"Success"},"ResponseCode":"NoError","Items":null}}} {"attributes":{"MessageDisposition":"SendAndSaveCopy"},"SavedItemFolderId":{"DistinguishedFolderId":{"attributes":{"Id":"sentitems"}}},"Items":{"Message":{"ItemClass":"IPM.Note","Subject":"Test EWS Email","Body":{"attributes":{"BodyType":"HTML"},"$value":"<b>This is a test email</b>"},"ExtendedProperty":{"ExtendedFieldURI":{"attributes":{"DistinguishedPropertySetId":"InternetHeaders","PropertyName":"0x8520","PropertyType":"String"}},"Value":"Omg!appeared"},"ToRecipients":{"Mailbox":[{"EmailAddress":"lokendranath.v@demo.com"}]},"IsRead":"false"}}}    

这是来自SOAPUI的Soap测试请求:-

    <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
      xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2010" />
  </soap:Header>
  <soap:Body>
    <m:CreateItem MessageDisposition="SendAndSaveCopy">
      <m:SavedItemFolderId>
        <t:DistinguishedFolderId Id="sentitems" />
      </m:SavedItemFolderId>
      <m:Items>
        <t:Message>
          <t:Subject>Saved with extendedPropertyDefinition of two days</t:Subject>
          <t:Body BodyType="Text">The expiration date is contained within the extended property.</t:Body>
        <t:ExtendedProperty>
        <t:ExtendedFieldURI PropertySetId ="Common" PropertyName="PSETID_Common" PropertyId="0x8520"  PropertyType="PT_BINARY"></t:ExtendedFieldURI>
        <t:Value>Approve</t:Value>
        </t:ExtendedProperty>
        <t:ExtendedProperty>
        <t:ExtendedFieldURI PropertySetId ="Common" PropertyName="PSETID_Common" PropertyId="0x8520"  PropertyType="PT_BINARY"></t:ExtendedFieldURI>
        <t:Value>Decline</t:Value>
        </t:ExtendedProperty>
          <t:ToRecipients>
            <t:Mailbox>
              <t:EmailAddress>kiranraj.p@demo.com</t:EmailAddress>
            </t:Mailbox>
          </t:ToRecipients>
        </t:Message>
      </m:Items>
    </m:CreateItem>
  </soap:Body>
</soap:Envelope>

返回以下响应:-

    <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="en-US">The request failed schema validation: The 'PropertySetId' attribute is invalid - The value 'Common' is invalid according to its datatype 'http://schemas.microsoft.com/exchange/services/2006/types:GuidType' - The Pattern constraint failed.</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>19</t:LineNumber>
               <t:LinePosition>23</t:LinePosition>
               <t:Violation>The 'PropertySetId' attribute is invalid - The value 'Common' is invalid according to its datatype 'http://schemas.microsoft.com/exchange/services/2006/types:GuidType' - The Pattern constraint failed.</t:Violation>
            </t:MessageXml>
         </detail>
      </s:Fault>
   </s:Body>
</s:Envelope>

1 个答案:

答案 0 :(得分:1)

这里是设置PidLidVerbStream流属性的示例,请注意,该属性是一个复杂的二进制流,已在https://msdn.microsoft.com/en-us/library/ee218541(v=exchg.80).aspx

中进行了说明。

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2013" />
  </soap:Header>
  <soap:Body>
    <m:CreateItem MessageDisposition="SaveOnly">
      <m:Items>
        <t:Message>
          <t:Subject>Test Mail</t:Subject>
          <t:Body BodyType="HTML">test</t:Body>
          <t:ExtendedProperty>
            <t:ExtendedFieldURI DistinguishedPropertySetId="Common" PropertyId="34080" PropertyType="Binary" />
            <t:Value>AgEHAAAAAAAAAAVSZXBseQhJUE0uTm90ZQdNZXNzYWdlAlJFBQAAAAAAAAAAAQAAAAAAAAACAAAAZgAAAAIAAAABAAAADFJlcGx5IHRvIEFsbAhJUE0uTm90ZQdNZXNzYWdlAlJFBQAAAAAAAAAAAQAAAAAAAAACAAAAZwAAAAMAAAACAAAAB0ZvcndhcmQISVBNLk5vdGUHTWVzc2FnZQJGVwUAAAAAAAAAAAEAAAAAAAAAAgAAAGgAAAAEAAAAAwAAAA9SZXBseSB0byBGb2xkZXIISVBNLlBvc3QEUG9zdAAFAAAAAAAAAAABAAAAAAAAAAIAAABsAAAACAAAAAQAAAADWWVzCElQTS5Ob3RlAANZZXMAAAAAAAAAAAABAAAAAgAAAAIAAAABAAAA/////wQAAAACTm8ISVBNLk5vdGUAAk5vAAAAAAAAAAAAAQAAAAIAAAACAAAAAgAAAP////8EAAAABU1heWJlCElQTS5Ob3RlAAVNYXliZQAAAAAAAAAAAAEAAAACAAAAAgAAAAMAAAD/////BAEFUgBlAHAAbAB5AAJSAEUADFIAZQBwAGwAeQAgAHQAbwAgAEEAbABsAAJSAEUAB0YAbwByAHcAYQByAGQAAkYAVwAPUgBlAHAAbAB5ACAAdABvACAARgBvAGwAZABlAHIAAANZAGUAcwADWQBlAHMAAk4AbwACTgBvAAVNAGEAeQBiAGUABU0AYQB5AGIAZQA=</t:Value>
          </t:ExtendedProperty>
          <t:ToRecipients>
            <t:Mailbox>
              <t:EmailAddress>gscales@datarumble.com</t:EmailAddress>
            </t:Mailbox>
          </t:ToRecipients>
        </t:Message>
      </m:Items>
    </m:CreateItem>
  </soap:Body>
</soap:Envelope>