nmarus / node-ews

A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API.
MIT License
115 stars 52 forks source link

Adding BccRecipients #61

Open mpodriezov opened 7 years ago

mpodriezov commented 7 years ago

Hi, I am trying to add bcc recipients to the email.

My args are:


      let ewsFunction = 'CreateItem';

      let ewsArgs = {
        "attributes": {
          "MessageDisposition": "SendAndSaveCopy"
        },
        "SavedItemFolderId": {
          "DistinguishedFolderId": {
            "attributes": {
              "Id": "sentitems"
            }
          }
        },
        "Items": {
          "Message": {
            "ItemClass": "IPM.Note",
            "Subject": "I am test",
            "Body": {
              "attributes": {
                "BodyType": "HTML"
              },
              "$value": "<b>Heeloo</b>"
            },
            "ToRecipients": {
              "Mailbox": [
                  { "EmailAddress": "test@test.com"}
              ]
            },
            "BccRecipients": {
              "Mailbox": [
                 { "EmailAddress": "other@test.com"}
              ]
            },
            "IsRead": "false"
          }
        }
      };

     // query ews, print resulting JSON to console
      this.ews.run(ewsFunction, ewsArgs)
        .then(result => {
          resolve(result);
        })
        .catch(err => {
          logger.log('error', 'Email transport error ', {msg: err.message, code: err.code, stack: err.stack});
          reject(err);
        });

It works very well without BccRecipients, but when I add this node my server keeps responding (translated to english from german):

error: Email transport error msg = soap11: Client: Error checking pattern request: The 'Message' element in Namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has an invalid subordinate element' BccRecipients' in Namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. The list of possible elements was expected: 'IsResponseRequested, References, ReplyTo' in Namespace 'http://schemas.microsoft.com/exchange/services/2006/types'., Code = undefined, stack = Error: soap11: Client: Error in the schema check of the request: The 'Message' element in Namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has an invalid subordinate element' BccRecipients' in Namespace 'http://schemas.microsoft .com / exchange / services / 2006 / types'. The list of possible elements was expected: 'IsResponseRequested, References, ReplyTo' in Namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.

Can you please help me?

kcastrotech commented 7 years ago

https://msdn.microsoft.com/en-us/library/office/aa494306(v=exchg.150).aspx It would appear your syntax is correct so my first suggestion is to force the type declaration ("t:") by changing the key to "t:BccRecipients" and try again.

mpodriezov commented 7 years ago

@kcastrotech Thank you, it worked for me. I guess something is wrong with json to xml convertor. Is it a bug?

kcastrotech commented 7 years ago

Glad that worked. Though I'm not entirely sure as to whether it's a bug or not. I did some cursory diagnostics when it happened to me and noticed on the generated XML that some of the keys were missing that "t:" and were being rejected even though it was perfectly valid. If it is a bug then it's somewhere on the node-soap side. It could also be a problem with your WSDL which is what node-soap uses to generate the properly formed XML message.