Skip to content

Instantly share code, notes, and snippets.

@gautamsi
Last active May 20, 2018 00:44
Show Gist options
  • Select an option

  • Save gautamsi/1c267504b5d4c759afc2a93def67e4d1 to your computer and use it in GitHub Desktop.

Select an option

Save gautamsi/1c267504b5d4c759afc2a93def67e4d1 to your computer and use it in GitHub Desktop.

Revisions

  1. gautamsi revised this gist Apr 6, 2017. 2 changed files with 68 additions and 21 deletions.
    40 changes: 19 additions & 21 deletions streamingtest.js
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,28 @@
    "use strict";
    var ews = require("ews-javascript-api");
    var credentials = require("../credentials");
    //import {MockXHRApi} from "./MockXHRApi";
    ews.EwsLogging.DebugLogEnabled = false;
    var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
    exch.Credentials = new ews.ExchangeCredentials(credentials.userName, credentials.password);
    exch.Url = new ews.Uri("https://outlook.office365.com/Ews/Exchange.asmx");
    exch.SubscribeToStreamingNotifications([new ews.FolderId(ews.WellKnownFolderName.Inbox)], ews.EventType.NewMail, ews.EventType.Created, ews.EventType.Deleted, ews.EventType.Modified, ews.EventType.Moved, ews.EventType.Copied, ews.EventType.FreeBusyChanged)
    .then(function (streamingSubscription) {
    var connection = new ews.StreamingSubscriptionConnection(exch, 1);
    console.log("subscribing....: ");
    connection.AddSubscription(streamingSubscription);
    connection.OnNotificationEvent.push(function (obj, notificationArgs) {
    console.log("notification received: ");
    ews.EwsLogging.Log(obj, true, true);
    // EwsLogging.Log(notificationArgs, true, true);
    });
    connection.OnDisconnect.push(function (connection, subscriptionErrorEventArgsInstance) {
    console.log("disconnecting...");
    ews.EwsLogging.Log(subscriptionErrorEventArgsInstance, true, true);
    //access subscriptionErrorEventArgsInstance
    //connection.Open();
    });
    connection.Open();
    }, function (err) {
    debugger;
    console.log("ERROR: --------------- ");
    console.log(err);
    });
    var connection = new ews.StreamingSubscriptionConnection(exch, 1);
    console.log("subscribing....: ");
    connection.AddSubscription(streamingSubscription);
    connection.OnNotificationEvent.push(function (obj, notificationArgs) {
    console.log("notification received: ");
    ews.EwsLogging.Log(obj, true, true);
    // EwsLogging.Log(notificationArgs, true, true);
    });
    connection.OnDisconnect.push(function (connection, subscriptionErrorEventArgsInstance) {
    console.log("disconnecting...");
    ews.EwsLogging.Log(subscriptionErrorEventArgsInstance, true, true);
    //access subscriptionErrorEventArgsInstance
    //connection.Open();
    });
    connection.Open();
    }, function (err) {
    console.log("ERROR: --------------- ");
    console.log(err);
    });
    49 changes: 49 additions & 0 deletions streamingtest.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    import {
    EwsLogging,
    ExchangeService,
    ExchangeVersion,
    ExchangeCredentials,
    Uri,
    FolderId,
    EventType,
    WellKnownFolderName,
    StreamingSubscriptionConnection,
    } from "ews-javascript-api";

    import credentials = require("../credentials");

    EwsLogging.DebugLogEnabled = false;
    var exch = new ExchangeService(ExchangeVersion.Exchange2013);
    exch.Credentials = new ExchangeCredentials(credentials.userName, credentials.password);
    exch.Url = new Uri("https://outlook.office365.com/Ews/Exchange.asmx");

    exch.SubscribeToStreamingNotifications(
    [new FolderId(WellKnownFolderName.Inbox)],
    EventType.NewMail,
    EventType.Created,
    EventType.Deleted,
    EventType.Modified,
    EventType.Moved,
    EventType.Copied,
    EventType.FreeBusyChanged)
    .then((streamingSubscription) => {
    let connection = new StreamingSubscriptionConnection(exch, 1);
    console.log("subscribing....: ");
    connection.AddSubscription(streamingSubscription);
    connection.OnNotificationEvent.push((obj, notificationArgs) => {
    console.log("notification received: ")
    EwsLogging.Log(obj, true, true);
    // EwsLogging.Log(notificationArgs, true, true);
    });
    connection.OnDisconnect.push((connection, subscriptionErrorEventArgsInstance) => {
    console.log("disconnecting...");
    EwsLogging.Log(subscriptionErrorEventArgsInstance, true, true);
    //access subscriptionErrorEventArgsInstance
    //connection.Open();
    });

    connection.Open();
    }, (err) => {
    console.log("ERROR: --------------- ");
    console.log(err);
    });
  2. gautamsi created this gist Apr 6, 2017.
    30 changes: 30 additions & 0 deletions streamingtest.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    "use strict";
    var ews = require("ews-javascript-api");
    var credentials = require("../credentials");
    //import {MockXHRApi} from "./MockXHRApi";
    ews.EwsLogging.DebugLogEnabled = false;
    var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
    exch.Credentials = new ews.ExchangeCredentials(credentials.userName, credentials.password);
    exch.Url = new ews.Uri("https://outlook.office365.com/Ews/Exchange.asmx");
    exch.SubscribeToStreamingNotifications([new ews.FolderId(ews.WellKnownFolderName.Inbox)], ews.EventType.NewMail, ews.EventType.Created, ews.EventType.Deleted, ews.EventType.Modified, ews.EventType.Moved, ews.EventType.Copied, ews.EventType.FreeBusyChanged)
    .then(function (streamingSubscription) {
    var connection = new ews.StreamingSubscriptionConnection(exch, 1);
    console.log("subscribing....: ");
    connection.AddSubscription(streamingSubscription);
    connection.OnNotificationEvent.push(function (obj, notificationArgs) {
    console.log("notification received: ");
    ews.EwsLogging.Log(obj, true, true);
    // EwsLogging.Log(notificationArgs, true, true);
    });
    connection.OnDisconnect.push(function (connection, subscriptionErrorEventArgsInstance) {
    console.log("disconnecting...");
    ews.EwsLogging.Log(subscriptionErrorEventArgsInstance, true, true);
    //access subscriptionErrorEventArgsInstance
    //connection.Open();
    });
    connection.Open();
    }, function (err) {
    debugger;
    console.log("ERROR: --------------- ");
    console.log(err);
    });