|
1 |
| -ews-typescript-api |
| 1 | +ews-javascript-api |
2 | 2 | ==================
|
| 3 | +##Exchange Web Service in JavaScript, available cross platform on Windows/Mac/Linux/Cordova |
3 | 4 |
|
4 |
| -EWS API for TypeScript/JavaScript - code based on OfficeDev/ews-managed-api |
| 5 | +EWS managed API for TypeScript/JavaScript - code ported from OfficeDev/ews-managed-api. availbale for node.js and mobile devices (cordova) |
| 6 | + |
| 7 | +All http operation is wrapped in promise using (WinJS promise or Q promise - configurable at build or in initialization). |
| 8 | +Coding style is highly compatible with EWS managed api 2.1 except it is async :). |
| 9 | + |
| 10 | +##Documentation |
| 11 | +more documents available in wiki (publishig soon) |
| 12 | + |
| 13 | +###install in node |
| 14 | +```shell |
| 15 | +[sudo] npm install ews-managed-api |
| 16 | +``` |
| 17 | + |
| 18 | +#### Use in node |
| 19 | +#####Autodiscover user settings |
| 20 | +```javascript |
| 21 | +//import ews module |
| 22 | +var ews = require('ews-javascript-api'); |
| 23 | +//create AutodiscoverService object |
| 24 | +var autod = new ews.AutodiscoverService(new ews.Uri("https://autodiscover-.outlook.com/autodiscover/autodiscover.svc"), ews.ExchangeVersion.Exchange2010); |
| 25 | +//you can omit url and it will autodiscover the url, version helps throw error on client side for unsupported operations.example - //var autod = new ews.AutodiscoverService(ews.ExchangeVersion.Exchange2010); |
| 26 | +//set credential for service |
| 27 | +autod.Credentials = new ews.ExchangeCredentials("userName", "password"); |
| 28 | +//create array to include list of desired settings |
| 29 | +var settings = [ |
| 30 | +ews.UserSettingName.InternalEwsUrl, |
| 31 | +ews.UserSettingName.ExternalEwsUrl, |
| 32 | +ews.UserSettingName.UserDisplayName, |
| 33 | +ews.UserSettingName.UserDN, |
| 34 | +ews.UserSettingName.EwsPartnerUrl, |
| 35 | +ews.UserSettingName.DocumentSharingLocations, |
| 36 | +ews.UserSettingName.MailboxDN, |
| 37 | +ews.UserSettingName.ActiveDirectoryServer, |
| 38 | +ews.UserSettingName.CasVersion, |
| 39 | +ews.UserSettingName.ExternalWebClientUrls, |
| 40 | +ews.UserSettingName.ExternalImap4Connections, |
| 41 | +ews.UserSettingName.AlternateMailboxes |
| 42 | +]; |
| 43 | +//get the setting |
| 44 | +autod. GetUserSettings([ "[email protected]", "[email protected]"], settings) |
| 45 | +.then(function (response) { |
| 46 | + //do what you want with user settings |
| 47 | + var tabcount = 0; |
| 48 | + var tabs = function () { return ews.StringHelper.Repeat("\t", tabcount); }; |
| 49 | + console.log(autod.Url.ToString()); |
| 50 | + //uncoment next line to see full response from autodiscover, you will need to add var util = require('util'); |
| 51 | + //console.log(util.inspect(response, { showHidden: false, depth: null, colors: true })); |
| 52 | + for (var _i = 0, _a = response.Responses; _i < _a.length; _i++) { |
| 53 | + var resp = _a[_i]; |
| 54 | + console.log(ews.StringHelper.Format("{0}settings for email: {1}", tabs(), resp.SmtpAddress)); |
| 55 | + tabcount++; |
| 56 | + for (var setting in resp.Settings) { |
| 57 | + console.log(ews.StringHelper.Format("{0}{1} = {2}", tabs(), ews.UserSettingName[setting], resp.Settings[setting])); |
| 58 | + } |
| 59 | + tabcount--; |
| 60 | + } |
| 61 | +}, function (e) { |
| 62 | + //log errors or do something with errors |
| 63 | +}); |
| 64 | +``` |
| 65 | + |
| 66 | +#####Use EWS operations |
| 67 | +Example of user availability |
| 68 | +```javascript |
| 69 | +var ews = require('ews-javascript-api'); |
| 70 | +//create ExchangeService object |
| 71 | +var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013); |
| 72 | +exch.Credentials = new ews.ExchangeCredentials("userName", "password"); |
| 73 | +//set ews endpoint url to use |
| 74 | +exch.Url = new ews.Uri("https://outlook.office365.com/Ews/Exchange.asmx"); // you can also use exch.AutodiscoverUrl |
| 75 | + |
| 76 | +var attendee =[ new ews.AttendeeInfo( "[email protected]"), new ews.AttendeeInfo( "[email protected]")]; |
| 77 | +//create timewindow object o request avaiability suggestions for next 48 hours, DateTime and TimeSpan object is created to mimic portion of .net datetime/timespan object using momentjs |
| 78 | +var timeWindow = new ews.TimeWindow(ews.DateTime.Now, new ews.DateTime(ews.DateTime.Now.TotalMilliSeconds + ews.TimeSpan.FromHours(48).asMilliseconds())); |
| 79 | +exch.GetUserAvailability(attendee, timeWindow, ews.AvailabilityData.FreeBusyAndSuggestions) |
| 80 | +.then(function (availabilityResponse) { |
| 81 | + //do what you want with user availability |
| 82 | +}, function (errors) { |
| 83 | + //log errors or do something with errors |
| 84 | +}); |
| 85 | + |
| 86 | +``` |
| 87 | + |
| 88 | +####Other Opetations |
| 89 | +#####Folder Operations |
| 90 | +* BindToFolder |
| 91 | +* CopyFolder |
| 92 | +* CreateFolder |
| 93 | +* DeleteFolder |
| 94 | +* EmptyFolder |
| 95 | +* FindFolders |
| 96 | +* LoadPropertiesForFolder |
| 97 | +* MarkAllItemsAsRead |
| 98 | +* MoveFolder |
| 99 | +* UpdateFolder |
| 100 | + |
| 101 | +#####Item Operations |
| 102 | + |
| 103 | +* ArchiveItem* |
| 104 | +* BindToItem* |
| 105 | +* CopyItem[s]* |
| 106 | +* CreateItem* |
| 107 | +* DeleteItem[s]* |
| 108 | +* FindAppointments* |
| 109 | +* FindItems |
| 110 | +* MarkAsJunk* |
| 111 | +* MoveItem* |
| 112 | +* SendItem* |
| 113 | +* UpdateItem[s]* |
| 114 | + |
| 115 | +#####Availability Operations |
| 116 | + |
| 117 | + |
| 118 | +* GetUserAvailability |
| 119 | + |
| 120 | +[*--Work in progress for next minor release] |
| 121 | + |
| 122 | +#####many more operations to be available soon |
| 123 | + |
| 124 | + |
| 125 | +####Use in Cordova |
| 126 | +AMD module for require.js to be included in build system, will be publishing bower module and documentation soon with. |
| 127 | + |
| 128 | + |
| 129 | +#Tests |
| 130 | +in progress.... |
| 131 | + |
| 132 | + |
| 133 | +#License |
| 134 | +Licensed under MIT |
0 commit comments