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



我在发送电子邮件时无法创建投票选项,我通过ExtendedProperty尽了最大努力,但运气不好,无法实现。我是nodejs的初学者,任何帮助/建议/指导都是可以接受的。

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>

这里有一个设置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>

最新更新