ews-simple
v0.3.0
Published
This package gives you an API to simplify work with ExchageWebService.
Downloads
57
Maintainers
Readme
ews-simple
Introduction
This package is build on top of ews-javascript-api and makes performing EWS operations easier.
API
ClientBuilder
This builder should allow you to configure EWS service with the specified url and auth data.
Supported methods:
- withVersion (value: ClientVersion) - configures ews version (default value is ClientVersion.Exchange2013)
- withUser (value: string) - configures ews user name
- withPwd (value: string) - configures user pwd
- withUri (value: string) - configures ews server uri
- withToken (value: string) - configures user authorization token
Example
const service = new ClientBuilder()
.withUser(`<EWS username>`)
.withPwd(`<EWS user pwd>`)
.build();
FindItemsResultBuilder
This builder should allow you to return search results using the specified input folder and query string.
Supported methods:
- withService (value: ews.ExchangeService) - allow set ews service to be linked to
- withFolder (value: FolderEnum) - allow to set ews folder to be looked into
- withTakeN (value: number) - allow to set the amount(default 1000) of items to be returned
- withOffset (value: number) - allow to set offset
- withOffsetBasePoint (value: 'start' | 'end') - allow to set base point(default start)
- withQueryString (value: string) - allow to set query string for search
- withMarkAsRead (value: boolean) - allow to set whether to mark letter as read or not
- withDelete (value: boolean) - allow to set whether do delete letter after read
- withGetRaw (value: boolean) - allow to set wherther to return raw items or parse them
- withSaveAttachments (value: boolean) - allow to set whether to download attachments or not
- withDownloadsFolder (value: string) - allow to set downloads folder for attachments(default is downloads)
- withRawBody (value: boolean)- allow to set whether to return raw body or parse it before return
Examples
Read (get Subject, Body and Received Date) 10 unread mails from Inbox
const items = await new FindItemsResultBuilder()
.withService(service)
.withFolder(FolderEnum.Inbox)
.withQueryString('isread:false')
.withTakeN(10)
.execute();
Read (keep them raw) 10 read mails from Favorites
const items = await new FindItemsResultBuilder()
.withService(service)
.withFolder(FolderEnum.Favorites)
.withQueryString('isread:true')
.withGetRaw(true)
.execute();
EmailMessageBuilder
This builder should allow you to send a email with the specified data.
- withService (value: ews.ExchangeService) - allow set ews service to be linked to
- withSubject (value: string) - allow to set message subject
- withBodyType (value: 'text' | 'htm;') - allow to set message body content type (default text)
- withBody (value: string) - allow to set message body content
- withTo (value: string[]) - allow to set a list of To recepients
- withСс (value: string[]) - allow to set a list of Сс recepients
- withFileAttachment (value: string) - allow to set path to file attachment
Examples
Send email
await new EmailMessageBuilder()
.withService(service)
.withSubject(<mail subject>)
.withBodyType(ews.BodyType.HTML)
.withBody(<mail body>)
.withTo(<recepients list>)
.execute();
Send email with file attachment
await new EmailMessageBuilder()
.withService(service)
.withSubject(<mail subject>)
.withBodyType(ews.BodyType.Text)
.withBody(<mail body>)
.withTo(<recepients list>)
.withFileAttachment(<file name>)
.execute();