public static void Run() { // Connect and log in to POP3 const string host = "host"; const int port = 110; const string username = "******"; const string password = "******"; Pop3Client client = new Pop3Client(host, port, username, password); try { MailQueryBuilder builder = new MailQueryBuilder(); // ExStart:CombineQueriesWithAND // Emails from specific host, get all emails that arrived before today and all emails that arrived since 7 days ago builder.From.Contains("SpecificHost.com"); builder.InternalDate.Before(DateTime.Now); builder.InternalDate.Since(DateTime.Now.AddDays(-7)); // ExEnd:CombineQueriesWithAND // Build the query and Get list of messages MailQuery query = builder.GetQuery(); Pop3MessageInfoCollection messages = client.ListMessages(query); Console.WriteLine("Pop3: " + messages.Count + " message(s) found."); builder = new MailQueryBuilder(); // ExStart:CombiningQueriesWithOR // Specify OR condition builder.Or(builder.Subject.Contains("test"), builder.From.Contains("*****@*****.**")); // ExEnd:CombiningQueriesWithOR // Build the query and Get list of messages query = builder.GetQuery(); messages = client.ListMessages(query); Console.WriteLine("Pop3: " + messages.Count + " message(s) found."); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { // Connect to EWS const string mailboxUri = "https://outlook.office365.com/ews/exchange.asmx"; const string username = "******"; const string password = "******"; const string domain = "domain"; try { IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password, domain); MailQueryBuilder builder = new MailQueryBuilder(); // ExStart:CombineQueriesWithAND // Emails from specific host, get all emails that arrived before today and all emails that arrived since 7 days ago builder.From.Contains("SpecificHost.com"); builder.InternalDate.Before(DateTime.Now); builder.InternalDate.Since(DateTime.Now.AddDays(-7)); // ExEnd:CombineQueriesWithAND // Build the query and Get list of messages MailQuery query = builder.GetQuery(); ExchangeMessageInfoCollection messages = client.ListMessages(client.MailboxInfo.InboxUri, query); Console.WriteLine("EWS: " + messages.Count + " message(s) found."); builder = new MailQueryBuilder(); // ExStart:CombiningQueriesWithOR builder.Or(builder.Subject.Contains("test"), builder.From.Contains("*****@*****.**")); // ExEnd:CombiningQueriesWithOR // Build the query and Get list of messages query = builder.GetQuery(); messages = client.ListMessages(client.MailboxInfo.InboxUri, query); Console.WriteLine("EWS: " + messages.Count + " message(s) found."); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { try { // Create instance of ExchangeClient class by giving credentials ExchangeClient client = new ExchangeClient("http://ex07sp1/exchange/Administrator", "user", "pwd", "domain"); MailQueryBuilder builder = new MailQueryBuilder(); // ExStart:CombineQueriesWithAND // Emails from specific host, get all emails that arrived before today and all emails that arrived since 7 days ago builder.From.Contains("SpecificHost.com"); builder.InternalDate.Before(DateTime.Now); builder.InternalDate.Since(DateTime.Now.AddDays(-7)); // ExEnd:CombineQueriesWithAND MailQuery query = builder.GetQuery(); ExchangeMessageInfoCollection messages = client.ListMessages(client.MailboxInfo.InboxUri, query, false); Console.WriteLine("Exchange: " + messages.Count + " message(s) found."); builder = new MailQueryBuilder(); // ExStart:CombiningQueriesWithOR // Specify OR condition builder.Or(builder.Subject.Contains("test"), builder.From.Contains("*****@*****.**")); // ExEnd:CombiningQueriesWithOR // Build the query and Get list of messages query = builder.GetQuery(); messages = client.ListMessages(client.MailboxInfo.InboxUri, query, false); Console.WriteLine("Exchange: " + messages.Count + " message(s) found."); } catch (Exception ex) { Console.WriteLine(ex.Message); } }