-
Notifications
You must be signed in to change notification settings - Fork 0
/
EWSClient.cs
34 lines (28 loc) · 1.11 KB
/
EWSClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Microsoft.Exchange.WebServices.Data;
using System;
using System.Net;
using System.Threading.Tasks;
namespace ewsfetcher
{
public class EWSClient
{
private ExchangeService _ews;
public EWSClient(string url, string domain, string username, string password)
{
_ews = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
_ews.Credentials = new WebCredentials(username, password, domain);
_ews.Url = new Uri(url);
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
}
public Task<FindItemsResults<Item>> Fetch(TimeSpan timeLimit)
{
var selectedTime = DateTime.Now.Add(timeLimit);
var searchFilter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, selectedTime);
return _ews.FindItems(WellKnownFolderName.Inbox, searchFilter, new ItemView(50));
}
public Task<EmailMessage> LoadMessage(ItemId messageId)
{
return EmailMessage.Bind(_ews, messageId);
}
}
}