Esempio n. 1
0
        public static void Run()
        {
            try
            {
                // ExStart:FetchMessageUsingEWS
                // Create instance of ExchangeWebServiceClient class by giving credentials
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

                // Call ListMessages method to list messages info from Inbox
                ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri);

                // Loop through the collection to get Message URI
                foreach (ExchangeMessageInfo msgInfo in msgCollection)
                {
                    String strMessageURI = msgInfo.UniqueUri;

                    // Now get the message details using FetchMessage()
                    MailMessage msg = client.FetchMessage(strMessageURI);

                    foreach (Attachment att in msg.Attachments)
                    {
                        Console.WriteLine("Attachment Name: " + att.Name);
                    }
                }
                // ExEnd:FetchMessageUsingEWS
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            const string      mailboxUri  = "https://exchange/ews/exchange.asmx";
            const string      domain      = @"";
            const string      username    = @"*****@*****.**";
            const string      password    = @"password";
            NetworkCredential credentials = new NetworkCredential(username, password, domain);
            IEWSClient        client      = EWSClient.GetEWSClient(mailboxUri, credentials);

            Console.WriteLine("Connected to Exchange 2010");
            // ExStart:CopyConversations
            // Find those Conversation Items in the Inbox folder which we want to copy
            ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);
            foreach (ExchangeConversation conversation in conversations)
            {
                Console.WriteLine("Topic: " + conversation.ConversationTopic);
                // Copy the conversation item based on some condition
                if (conversation.ConversationTopic.Contains("test email") == true)
                {
                    client.CopyConversationItems(conversation.ConversationId, client.MailboxInfo.DeletedItemsUri);
                    Console.WriteLine("Copied the conversation item to another folder");
                }
            }
            // ExEnd:CopyConversations
        }
Esempio n. 3
0
        public static void Run()
        {
            try
            {
                // Set mailboxURI, Username, password, domain information
                string            mailboxUri  = "https://ex2010/ews/exchange.asmx";
                string            username    = "******";
                string            password    = "******";
                string            domain      = "ex2010.local";
                NetworkCredential credentials = new NetworkCredential(username, password, domain);
                IEWSClient        client      = EWSClient.GetEWSClient(mailboxUri, credentials);

                // ExStart:ExpandPublicDistributionList

                MailAddressCollection members = client.ExpandDistributionList(new MailAddress("*****@*****.**"));
                foreach (MailAddress member in members)
                {
                    Console.WriteLine(member.Address);
                }
                // ExEnd:ExpandPublicDistributionList
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            try
            {
                string            mailboxUri  = "https://ex2010/ews/exchange.asmx";
                string            username    = "******";
                string            password    = "******";
                string            domain      = "ex2010.local";
                NetworkCredential credentials = new NetworkCredential(username, password, domain);

                // ExStart:UpdateContactInformationUsingEWS
                IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);

                // List all the contacts and Loop through all contacts
                Contact[] contacts = client.GetContacts(client.MailboxInfo.ContactsUri);
                Contact   contact  = contacts[0];
                Console.WriteLine("Name: " + contact.DisplayName);
                contact.DisplayName = "David Ch";
                client.UpdateContact(contact);
                // ExEnd:UpdateContactInformationUsingEWS
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 5
0
        // ExStart:ListFoldersFromExchangeServer
        public static void Run()
        {
            try
            {
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
                Console.WriteLine("Downloading all messages from Inbox....");

                ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
                Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri);
                string rootUri = client.GetMailboxInfo().RootUri;
                // List all the folders from Exchange server
                ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(rootUri);
                foreach (ExchangeFolderInfo folderInfo in folderInfoCollection)
                {
                    // Call the recursive method to read messages and get sub-folders
                    ListSubFolders(client, folderInfo);
                }

                Console.WriteLine("All messages downloaded.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            // ExStart:SynchronizeFolderItems
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            MailMessage message1 = new MailMessage("*****@*****.**", "*****@*****.**", "EMAILNET-34738 - " + Guid.NewGuid().ToString(),
                                                   "EMAILNET-34738 Sync Folder Items");

            client.Send(message1);

            MailMessage message2 = new MailMessage("*****@*****.**", "*****@*****.**", "EMAILNET-34738 - " + Guid.NewGuid().ToString(),
                                                   "EMAILNET-34738 Sync Folder Items");

            client.Send(message2);

            ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri);

            SyncFolderResult result = client.SyncFolder(client.MailboxInfo.InboxUri, null);

            Console.WriteLine(result.NewItems.Count);
            Console.WriteLine(result.ChangedItems.Count);
            Console.WriteLine(result.ReadFlagChanged.Count);
            Console.WriteLine(result.DeletedItems.Length);
            // ExEnd:SynchronizeFolderItems
        }
        public static void Run()
        {
            // Create and initialize credentials
            var credentials = new NetworkCredential("username", "12345");

            // Create instance of ExchangeClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            // Get all tasks info collection from exchange
            ExchangeMessageInfoCollection tasks = client.ListMessages(client.MailboxInfo.TasksUri);

            // Parse all the tasks info in the list
            foreach (ExchangeMessageInfo info in tasks)
            {
                // Fetch task from exchange using current task info
                ExchangeTask task = client.FetchTask(info.UniqueUri);

                // Update the task status to NotStarted
                task.Status = ExchangeTaskStatus.NotStarted;

                // Set the task due date
                task.DueDate = new DateTime(2013, 2, 26);

                // Set task priority
                task.Priority = MailPriority.Low;

                // Update task on exchange
                client.UpdateTask(task);
            }

            Console.WriteLine(Environment.NewLine + "Task updated on Exchange Server successfully.");
        }
Esempio n. 8
0
        public static void Run()
        {
            try
            {
                // Set mailboxURI, Username, password, domain information
                string            mailboxUri  = "https://ex2010/ews/exchange.asmx";
                string            username    = "******";
                string            password    = "******";
                string            domain      = "ex2010.local";
                NetworkCredential credentials = new NetworkCredential(username, password, domain);
                IEWSClient        client      = EWSClient.GetEWSClient(mailboxUri, credentials);

                // ExStart:SendEmailToPrivateDistributionList

                ExchangeDistributionList[] distributionLists = client.ListDistributionLists();
                MailAddress distributionListAddress          = distributionLists[0].ToMailAddress();
                MailMessage message = new MailMessage(new MailAddress("*****@*****.**"), distributionListAddress);
                message.Subject = "sendToPrivateDistributionList";
                client.Send(message);
                // ExEnd:SendEmailToPrivateDistributionList
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart: SendCalendarInvitation
                using (IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"))
                {
                    // delegate calendar access permission
                    ExchangeDelegateUser delegateUser = new ExchangeDelegateUser("*****@*****.**", ExchangeDelegateFolderPermissionLevel.NotSpecified);
                    delegateUser.FolderPermissions.CalendarFolderPermissionLevel = ExchangeDelegateFolderPermissionLevel.Reviewer;
                    client.DelegateAccess(delegateUser, "*****@*****.**");

                    // Create invitation
                    MapiMessage           mapiMessage = client.CreateCalendarSharingInvitationMessage("*****@*****.**");
                    MailConversionOptions options     = new MailConversionOptions();
                    options.ConvertAsTnef = true;
                    MailMessage mail = mapiMessage.ToMailMessage(options);
                    client.Send(mail);
                }
                // ExEnd: SendCalendarInvitation
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 10
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Exchange();

            try
            {
                // ExStart:SaveMessagesInMSGFormatExchangeEWS
                // Create instance of EWSClient class by giving credentials
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

                // Call ListMessages method to list messages info from Inbox
                ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri);

                int count = 0;
                // Loop through the collection to get Message URI
                foreach (ExchangeMessageInfo msgInfo in msgCollection)
                {
                    string strMessageURI = msgInfo.UniqueUri;

                    // Now get the message details using FetchMessage() and Save message as Msg
                    MailMessage message = client.FetchMessage(strMessageURI);
                    message.Save(dataDir + (count++) + "_out.msg", SaveOptions.DefaultMsgUnicode);
                }
                // ExEnd:SaveMessagesInMSGFormatExchangeEWS
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 11
0
        private static void DownloadAllMessages()
        {
            try
            {
                string rootFolder = domain + "-" + username;
                Directory.CreateDirectory(rootFolder);
                string inboxFolder = rootFolder + "\\Inbox";
                Directory.CreateDirectory(inboxFolder);

                Console.WriteLine("Downloading all messages from Inbox....");
                // Create instance of IEWSClient class by giving credentials
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", username, password, domain);

                ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
                Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri);
                string rootUri = client.GetMailboxInfo().RootUri;
                // List all the folders from Exchange server
                ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(rootUri);
                foreach (ExchangeFolderInfo folderInfo in folderInfoCollection)
                {
                    // Call the recursive method to read messages and get sub-folders
                    ListMessagesInFolder(client, folderInfo, rootFolder);
                }

                Console.WriteLine("All messages downloaded.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            // ExStart:SendMeetingRequestsUsingEWS
            try
            {
                // Create instance of IEWSClient class by giving credentials
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

                // create the meeting request
                Appointment app = new Appointment("meeting request", DateTime.Now.AddHours(1), DateTime.Now.AddHours(1.5), "*****@*****.**", "*****@*****.**");
                app.Summary     = "meeting request summary";
                app.Description = "description";
                // set recurrence pattern for this appointment
                RecurrencePattern pattern = new DailyRecurrencePattern(DateTime.Now.AddDays(5));
                app.RecurrencePattern = pattern;

                // create the message and set the meeting request
                MailMessage msg = new MailMessage();
                msg.From       = "*****@*****.**";
                msg.To         = "*****@*****.**";
                msg.IsBodyHtml = true;
                msg.HtmlBody   = "<h3>HTML Heading</h3><p>Email Message detail</p>";
                msg.Subject    = "meeting request";
                msg.AddAlternateView(app.RequestApointment(0));

                // send the appointment
                client.Send(msg);
                Console.WriteLine("Appointment request sent");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:SendMeetingRequestsUsingEWS
        }
Esempio n. 13
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir  = RunExamples.GetDataDir_Exchange();
            string dstEmail = dataDir + "Message.msg";

            // Create instance of ExchangeClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            MailMessageLoadOptions loadOptions = new MailMessageLoadOptions();

            loadOptions.MessageFormat         = MessageFormat.Msg;
            loadOptions.FileCompatibilityMode = FileCompatibilityMode.PreserveTnefAttachments;

            // load task from .msg file
            MailMessage eml = MailMessage.Load(dstEmail, loadOptions);

            eml.From = "*****@*****.**";
            eml.To.Clear();
            eml.To.Add(new Aspose.Email.Mail.MailAddress("*****@*****.**"));

            client.Send(eml);

            Console.WriteLine(Environment.NewLine + "Task sent on Exchange Server successfully.");
        }
        public static void Run()
        {
            // ExStart:DeleteMessagesFromusingEWS

            // Create instance of IEWSClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();

            // List all messages from Inbox folder
            Console.WriteLine("Listing all messages from Inbox....");
            ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri);

            foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
            {
                // Delete message based on some criteria
                if (msgInfo.Subject != null && msgInfo.Subject.ToLower().Contains("delete") == true)
                {
                    client.DeleteItem(msgInfo.UniqueUri, DeletionOptions.DeletePermanently); // EWS
                    Console.WriteLine("Message deleted...." + msgInfo.Subject);
                }
                else
                {
                    // Do something else
                }
            }
            // ExEnd:DeleteMessagesFromusingEWS
        }
Esempio n. 15
0
        public static void Run()
        {
            // ExStart:UpdateRuleOntheExchangeServer
            // Set mailboxURI, Username, password, domain information
            string mailboxURI = "https://ex2010/ews/exchange.asmx";
            string username   = "******";
            string password   = "******";
            string domain     = "ex2010.local";

            // Connect to the Exchange Server
            NetworkCredential credential = new NetworkCredential(username, password, domain);
            IEWSClient        client     = EWSClient.GetEWSClient(mailboxURI, credential);

            Console.WriteLine("Connected to Exchange server");

            // Get all Inbox Rules
            InboxRule[] inboxRules = client.GetInboxRules();

            // Loop through each rule
            foreach (InboxRule inboxRule in inboxRules)
            {
                Console.WriteLine("Display Name: " + inboxRule.DisplayName);
                if (inboxRule.DisplayName == "Message from client ABC")
                {
                    Console.WriteLine("Updating the rule....");
                    inboxRule.Conditions.FromAddresses[0] = new MailAddress("*****@*****.**", true);
                    client.UpdateInboxRule(inboxRule);
                }
            }
            // ExEnd:UpdateRuleOntheExchangeServer
        }
Esempio n. 16
0
        public static void Run()
        {
            // The path to the File directory.
            string dataDir  = RunExamples.GetDataDir_Exchange();
            string dstEmail = dataDir + "Message.eml";

            // Create instance of ExchangeClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            // load task from .eml file
            EmlLoadOptions loadOptions = new EmlLoadOptions();

            loadOptions.PrefferedTextEncoding   = Encoding.UTF8;
            loadOptions.PreserveTnefAttachments = true;

            // load task from .msg file
            MailMessage eml = MailMessage.Load(dstEmail, loadOptions);

            eml.From = "*****@*****.**";
            eml.To.Clear();
            eml.To.Add(new MailAddress("*****@*****.**"));

            client.Send(eml);

            Console.WriteLine(Environment.NewLine + "Task sent on Exchange Server successfully.");
        }
        public static void Run()
        {
            // ExStart:CreateREAndFWMessages
            string dataDir = RunExamples.GetDataDir_Exchange();

            const string      mailboxUri = "https://exchange.domain.com/ews/Exchange.asmx";
            const string      domain     = @"";
            const string      username   = @"username";
            const string      password   = @"password";
            NetworkCredential credential = new NetworkCredential(username, password, domain);
            IEWSClient        client     = EWSClient.GetEWSClient(mailboxUri, credential);

            try
            {
                MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "TestMailRefw - " + Guid.NewGuid().ToString(),
                                                      "TestMailRefw Implement ability to create RE and FW messages from source MSG file");

                client.Send(message);

                ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri);
                if (messageInfoCol.Count == 1)
                {
                    Console.WriteLine("1 message in Inbox");
                }
                else
                {
                    Console.WriteLine("Error! No message in Inbox");
                }

                MailMessage message1 = new MailMessage("*****@*****.**", "*****@*****.**", "TestMailRefw - " + Guid.NewGuid().ToString(),
                                                       "TestMailRefw Implement ability to create RE and FW messages from source MSG file");

                client.Send(message1);
                messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri);

                if (messageInfoCol.Count == 2)
                {
                    Console.WriteLine("2 messages in Inbox");
                }
                else
                {
                    Console.WriteLine("Error! No new message in Inbox");
                }

                MailMessage message2 = new MailMessage("*****@*****.**", "*****@*****.**", "TestMailRefw - " + Guid.NewGuid().ToString(),
                                                       "TestMailRefw Implement ability to create RE and FW messages from source MSG file");
                message2.Attachments.Add(Attachment.CreateAttachmentFromString("Test attachment 1", "Attachment Name 1"));
                message2.Attachments.Add(Attachment.CreateAttachmentFromString("Test attachment 2", "Attachment Name 2"));

                // Reply, Replay All and forward Message
                client.Reply(message2, messageInfoCol[0]);
                client.ReplyAll(message2, messageInfoCol[0]);
                client.Forward(message2, messageInfoCol[0]);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error in program" + ex.Message);
            }
            // ExEnd:CreateREAndFWMessages
        }
Esempio n. 18
0
        public static void Run()
        {
            // ExStart:MoveMessageFromOneFolderToAnotherusingEWS
            // Create instance of IEWSClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();

            // List all messages from Inbox folder
            Console.WriteLine("Listing all messages from Inbox....");
            ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri);

            foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
            {
                // Move message to "Processed" folder, after processing certain messages based on some criteria
                if (msgInfo.Subject != null &&
                    msgInfo.Subject.ToLower().Contains("process this message") == true)
                {
                    client.MoveItem(mailboxInfo.DeletedItemsUri, msgInfo.UniqueUri); // EWS
                    Console.WriteLine("Message moved...." + msgInfo.Subject);
                }
                else
                {
                    // Do something else
                }
            }
            // ExEnd:MoveMessageFromOneFolderToAnotherusingEWS
        }
        static void Run()
        {
            ///<summary>
            /// This example shows how to list messages from Exchange Server with Paging support
            /// Introduced in Aspose.Email for .NET 6.4.0
            /// ExchangeMessagePageInfo ListMessagesByPage(string folder, int itemsPerPage);
            /// ExchangeMessagePageInfo ListMessagesByPage(string folder, int itemsPerPage, int offset);
            /// ExchangeMessagePageInfo ListMessagesByPage(string folder, int itemsPerPage, int pageOffset, ExchangeListMessagesOptions options);
            /// ExchangeMessagePageInfo ListMessagesByPage(string folder, PageInfo pageInfo);
            /// ExchangeMessagePageInfo ListMessagesByPage(string folder, PageInfo pageInfo, ExchangeListMessagesOptions options);
            ///</summary>
            // ExStart: PagingSupportForListingMessages
            using (IEWSClient client = EWSClient.GetEWSClient("exchange.domain.com", "username", "password"))
            {
                try
                {
                    // Create some test messages to be added to server for retrieval later
                    int         messagesNum  = 12;
                    int         itemsPerPage = 5;
                    MailMessage message      = null;
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35157_1 - " + Guid.NewGuid().ToString(),
                            "EMAILNET-35157 Move paging parameters to separate class");
                        client.AppendMessage(client.MailboxInfo.InboxUri, message);
                    }
                    // Verfiy that the messages have been added to the server
                    ExchangeMessageInfoCollection totalMessageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri);
                    Console.WriteLine(totalMessageInfoCol.Count);

                    ////////////////// RETREIVING THE MESSAGES USING PAGING SUPPORT ////////////////////////////////////

                    List <ExchangeMessagePageInfo> pages    = new List <ExchangeMessagePageInfo>();
                    ExchangeMessagePageInfo        pageInfo = client.ListMessagesByPage(client.MailboxInfo.InboxUri, itemsPerPage);
                    // Total Pages Count
                    Console.WriteLine(pageInfo.TotalCount);

                    pages.Add(pageInfo);
                    while (!pageInfo.LastPage)
                    {
                        pageInfo = client.ListMessagesByPage(client.MailboxInfo.InboxUri, itemsPerPage, pageInfo.PageOffset + 1);
                        pages.Add(pageInfo);
                    }
                    int retrievedItems = 0;
                    foreach (ExchangeMessagePageInfo pageCol in pages)
                    {
                        retrievedItems += pageCol.Items.Count;
                    }
                    // Verify total message count using paging
                    Console.WriteLine(retrievedItems);
                }
                finally
                {
                }
            }
            // ExEnd: PagingSupportForListingMessages
        }
        public static void Run()
        {
            // ExStart:CreateNewRuleOntheExchangeServer
            // Set Exchange Server web service URL, Username, password, domain information
            string mailboxURI = "https://ex2010/ews/exchange.asmx";
            string username   = "******";
            string password   = "******";
            string domain     = "ex2010.local";

            // Connect to the Exchange Server
            NetworkCredential credential = new NetworkCredential(username, password, domain);
            IEWSClient        client     = EWSClient.GetEWSClient(mailboxURI, credential);

            Console.WriteLine("Connected to Exchange server");

            InboxRule rule = new InboxRule();

            rule.DisplayName = "Message from client ABC";

            // Add conditions
            RulePredicates newRules = new RulePredicates();

            // Set Subject contains string "ABC" and Add the conditions
            newRules.ContainsSubjectStrings.Add("ABC");
            newRules.FromAddresses.Add(new MailAddress("*****@*****.**", true));
            rule.Conditions = newRules;

            // Add Actions and Move the message to a folder
            RuleActions newActions = new RuleActions();

            newActions.MoveToFolder = "120:AAMkADFjMjNjMmNjLWE3NzgtNGIzNC05OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABbwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA==";
            rule.Actions            = newActions;
            client.CreateInboxRule(rule);
            // ExEnd:CreateNewRuleOntheExchangeServer
        }
        public static void Run()
        {
            // ExStart:CreateFoldersOnExchangeServerMailbox

            // Create instance of EWSClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            string             inbox          = client.MailboxInfo.InboxUri;
            string             folderName1    = "EMAILNET-35054";
            string             subFolderName0 = "2015";
            string             folderName2    = folderName1 + "/" + subFolderName0;
            string             folderName3    = folderName1 + " / 2015";
            ExchangeFolderInfo rootFolderInfo = null;
            ExchangeFolderInfo folderInfo     = null;

            try
            {
                client.UseSlashAsFolderSeparator = true;
                client.CreateFolder(client.MailboxInfo.InboxUri, folderName1);
                client.CreateFolder(client.MailboxInfo.InboxUri, folderName2);
            }
            finally
            {
                if (client.FolderExists(inbox, folderName1, out rootFolderInfo))
                {
                    if (client.FolderExists(inbox, folderName2, out folderInfo))
                    {
                        client.DeleteFolder(folderInfo.Uri, true);
                    }
                    client.DeleteFolder(rootFolderInfo.Uri, true);
                }
            }
            // ExEnd:CreateFoldersOnExchangeServerMailbox
        }
        public static void Run()
        {
            // ExStart:EnumeratMessagesWithPaginginEWS
            // Create instance of ExchangeWebServiceClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "*****@*****.**", "LoveAir1993");

            // Call ListMessages method to list messages info from Inbox
            ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.GetMailboxInfo().InboxUri);

            try
            {
                int itemsPerPage = 5;
                List <ExchangeMessageInfoCollection> pages = new List <ExchangeMessageInfoCollection>();
                ExchangeMessageInfoCollection        pagedMessageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, itemsPerPage);
                pages.Add(pagedMessageInfoCol);

                while (!pagedMessageInfoCol.LastPage)
                {
                    pagedMessageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, itemsPerPage, pagedMessageInfoCol.LastItemOffset.Value + 1);
                    pages.Add(pagedMessageInfoCol);
                }

                pagedMessageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, itemsPerPage);

                while (!pagedMessageInfoCol.LastPage)
                {
                    client.ListMessages(client.MailboxInfo.InboxUri, pagedMessageInfoCol, itemsPerPage, pagedMessageInfoCol.LastItemOffset.Value + 1);
                }
            }
            finally
            {
            }
            // ExEnd:EnumeratMessagesWithPaginginEWS
        }
Esempio n. 23
0
        public static void Run()
        {
            try
            {
                // ExStart:SendTaskRequestUsingIEWSClient
                string dataDir = RunExamples.GetDataDir_Exchange();
                // Create instance of ExchangeClient class by giving credentials
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

                MsgLoadOptions options = new MsgLoadOptions();
                options.PreserveTnefAttachments = true;

                // load task from .msg file
                MailMessage eml = MailMessage.Load(dataDir + "task.msg", options);
                eml.From = "*****@*****.**";
                eml.To.Clear();
                eml.To.Add(new MailAddress("*****@*****.**"));
                client.Send(eml);
                // ExEnd:SendTaskRequestUsingIEWSClient
            }
            catch (Exception ex)
            {
                Console.Write(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);

                // ExStart:CaseSensitiveEmailsFiltering
                // Query building by means of ExchangeQueryBuilder class
                ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
                builder.Subject.Contains("Newsletter", true);
                builder.InternalDate.On(DateTime.Now);
                MailQuery query = builder.GetQuery();
                // ExEnd:CaseSensitiveEmailsFiltering

                // Get list of messages
                ExchangeMessageInfoCollection messages = client.ListMessages(client.MailboxInfo.InboxUri, query, false);
                Console.WriteLine("EWS: " + messages.Count + " message(s) found.");

                // Disconnect from EWS
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:EnumeratMessagesWithPaginginEWS
                // Create instance of ExchangeWebServiceClient class by giving credentials
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "UserName", "Password");

                // Call ListMessages method to list messages info from Inbox
                ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.GetMailboxInfo().InboxUri);
                int             itemsPerPage        = 5;
                List <PageInfo> pages               = new List <PageInfo>();
                PageInfo        pagedMessageInfoCol = client.ListMessagesByPage(client.MailboxInfo.InboxUri, itemsPerPage);
                pages.Add(pagedMessageInfoCol);
                while (!pagedMessageInfoCol.LastPage)
                {
                    pagedMessageInfoCol = client.ListMessagesByPage(client.MailboxInfo.InboxUri, itemsPerPage);
                    pages.Add(pagedMessageInfoCol);
                }
                pagedMessageInfoCol = client.ListMessagesByPage(client.MailboxInfo.InboxUri, itemsPerPage);
                while (!pagedMessageInfoCol.LastPage)
                {
                    client.ListMessages(client.MailboxInfo.InboxUri);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
            finally
            {
            }
            // ExEnd:EnumeratMessagesWithPaginginEWS
        }
Esempio n. 26
0
        public static void Run()
        {
            // ExStart:AccessCustomFolderUsingExchangeWebServiceClient
            // Create instance of EWSClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            // Create ExchangeMailboxInfo, ExchangeMessageInfoCollection instance
            ExchangeMailboxInfo           mailbox       = client.GetMailboxInfo();
            ExchangeMessageInfoCollection messages      = null;
            ExchangeFolderInfo            subfolderInfo = new ExchangeFolderInfo();

            // Check if specified custom folder exisits and Get all the messages info from the target Uri
            client.FolderExists(mailbox.InboxUri, "TestInbox", out subfolderInfo);
            messages = client.FindMessages(subfolderInfo.Uri);

            // Parse all the messages info collection
            foreach (ExchangeMessageInfo info in messages)
            {
                string strMessageURI = info.UniqueUri;
                // now get the message details using FetchMessage()
                MailMessage msg = client.FetchMessage(strMessageURI);
                Console.WriteLine("Subject: " + msg.Subject);
            }
            // ExEnd:AccessCustomFolderUsingExchangeWebServiceClient
        }
        public static void Run()
        {
            try
            {
                // ExStart:SaveMessagesToMemoryStream
                string datadir = RunExamples.GetDataDir_Exchange();
                // Create instance of EWSClient class by giving credentials
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

                // Call ListMessages method to list messages info from Inbox
                ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri);

                // Loop through the collection to get Message URI
                foreach (ExchangeMessageInfo msgInfo in msgCollection)
                {
                    string strMessageURI = msgInfo.UniqueUri;

                    // Now save the message in memory stream
                    MemoryStream stream = new MemoryStream();
                    client.SaveMessage(strMessageURI, datadir + stream);
                }
                // ExEnd:SaveMessagesToMemoryStream
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:DeleteContactsFromExchangeServerUsingEWS
                // Create instance of EWSClient class by giving credentials
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

                string    strContactToDelete = "John Teddy";
                Contact[] contacts           = client.GetContacts(client.MailboxInfo.ContactsUri);
                foreach (Contact contact in contacts)
                {
                    if (contact.DisplayName.Equals(strContactToDelete))
                    {
                        client.DeleteItem(contact.Id.EWSId, DeletionOptions.DeletePermanently);
                    }
                }
                client.Dispose();
                // ExEnd:DeleteContactsFromExchangeServerUsingEWS
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            const string      mailboxUri  = "https://exchange/ews/exchange.asmx";
            const string      domain      = @"";
            const string      username    = @"*****@*****.**";
            const string      password    = @"password";
            NetworkCredential credentials = new NetworkCredential(username, password, domain);

            // ExStart:FindConversationsOnExchangeServer
            IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);

            Console.WriteLine("Connected to Exchange 2010");

            // Find Conversation Items in the Inbox folder
            ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);
            // Show all conversations
            foreach (ExchangeConversation conversation in conversations)
            {
                // Display conversation properties like Id and Topic
                Console.WriteLine("Topic: " + conversation.ConversationTopic);
                Console.WriteLine("Flag Status: " + conversation.FlagStatus.ToString());
                Console.WriteLine();
            }
            // ExEnd:FindConversationsOnExchangeServer
        }
        public static void Run()
        {
            // ExStart:GetMailTips
            // Create instance of EWSClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            Console.WriteLine("Connected to Exchange server...");
            // Provide mail tips options
            MailAddressCollection addrColl = new MailAddressCollection();

            addrColl.Add(new MailAddress("*****@*****.**", true));
            addrColl.Add(new MailAddress("*****@*****.**", true));
            GetMailTipsOptions options = new GetMailTipsOptions("*****@*****.**", addrColl, MailTipsType.All);

            // Get Mail Tips
            MailTips[] tips = client.GetMailTips(options);

            // Display information about each Mail Tip
            foreach (MailTips tip in tips)
            {
                // Display Out of office message, if present
                if (tip.OutOfOffice != null)
                {
                    Console.WriteLine("Out of office: " + tip.OutOfOffice.ReplyBody.Message);
                }

                // Display the invalid email address in recipient, if present
                if (tip.InvalidRecipient == true)
                {
                    Console.WriteLine("The recipient address is invalid: " + tip.RecipientAddress);
                }
            }
            // ExEnd:GetMailTips
        }