예제 #1
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);
            }
        }
        private void PopulateFoldersExchangeClient(IEWSClient client, string folderUri, TreeNodeCollection nodes)
        {
            // Get subfolders of the current URI
            ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(folderUri);

            // Add the subfolders to the current tree node
            foreach (ExchangeFolderInfo folderInfo in folderInfoCollection)
            {
                if (folderInfo.DisplayName.Equals("Conversation Action Settings", StringComparison.InvariantCultureIgnoreCase) ||
                    folderInfo.DisplayName.Equals("Quick Step Settings", StringComparison.InvariantCultureIgnoreCase) ||
                    folderInfo.DisplayName.Equals("Contacts", StringComparison.InvariantCultureIgnoreCase) ||
                    folderInfo.DisplayName.Equals("News Feed", StringComparison.InvariantCultureIgnoreCase) ||
                    folderInfo.DisplayName.Equals("Notes", StringComparison.InvariantCultureIgnoreCase) ||
                    folderInfo.DisplayName.Equals("Outbox", StringComparison.InvariantCultureIgnoreCase) ||
                    folderInfo.DisplayName.Equals("Suggested Contacts", StringComparison.InvariantCultureIgnoreCase) ||
                    folderInfo.DisplayName.Equals("Sync Issues", StringComparison.InvariantCultureIgnoreCase) ||
                    folderInfo.DisplayName.Equals("Tasks", StringComparison.InvariantCultureIgnoreCase) ||
                    folderInfo.DisplayName.Equals("Calendar", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    // do not add any of these folder
                }
                else
                {
                    TreeNode node = new TreeNode(folderInfo.DisplayName, folderInfo.Uri);
                    nodes.Add(node);
                    // If there are subfolders, call function recursively to add its subfolders
                    if (folderInfo.ChildFolderCount > 0)
                    {
                        PopulateFoldersExchangeClient(client, folderInfo.Uri, node.ChildNodes);
                    }
                }
            }
        }
예제 #3
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);
            }
        }
예제 #4
0
        // ExStart:ListFoldersUsingExchangeClient
        public static void Run()
        {
            try
            {
                ExchangeClient client = new ExchangeClient("http://ex07sp1/exchange/Administrator", "user", "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);
            }
        }
예제 #5
0
        public static void Run()
        {
            // ExStart:RetrieveFolderPermissionsUsingExchangeWebServiceClient
            string folderName = "DesiredFolderName";

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

            ExchangeFolderInfoCollection       folders     = client.ListPublicFolders();
            ExchangeFolderPermissionCollection permissions = new ExchangeFolderPermissionCollection();

            ExchangeFolderInfo publicFolder = null;

            try
            {
                foreach (ExchangeFolderInfo folderInfo in folders)
                {
                    if (folderInfo.DisplayName.Equals(folderName))
                    {
                        publicFolder = folderInfo;
                    }
                }

                if (publicFolder == null)
                {
                    Console.WriteLine("public folder was not created in the root public folder");
                }

                ExchangePermissionCollection folderPermissionCol = client.GetFolderPermissions(publicFolder.Uri);
                foreach (ExchangeBasePermission perm in folderPermissionCol)
                {
                    ExchangeFolderPermission permission = perm as ExchangeFolderPermission;
                    if (permission == null)
                    {
                        Console.WriteLine("Permission is null.");
                    }
                    else
                    {
                        Console.WriteLine("User's primary smtp address: {0}", permission.UserInfo.PrimarySmtpAddress);
                        Console.WriteLine("User can create Items: {0}", permission.CanCreateItems.ToString());
                        Console.WriteLine("User can delete Items: {0}", permission.DeleteItems.ToString());
                        Console.WriteLine("Is Folder Visible: {0}", permission.IsFolderVisible.ToString());
                        Console.WriteLine("Is User owner of this folder: {0}", permission.IsFolderOwner.ToString());
                        Console.WriteLine("User can read items: {0}", permission.ReadItems.ToString());
                    }
                }
                ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
                //Get the Permissions for the Contacts and Calendar Folder
                ExchangePermissionCollection contactsPermissionCol = client.GetFolderPermissions(mailboxInfo.ContactsUri);
                ExchangePermissionCollection calendarPermissionCol = client.GetFolderPermissions(mailboxInfo.CalendarUri);
            }
            finally
            {
                //Do the needfull
            }
            // ExEnd:RetrieveFolderPermissionsUsingExchangeWebServiceClient
        }
예제 #6
0
        private static void ReadPublicFolders()
        {
            NetworkCredential credential = new NetworkCredential(username, password, domain);
            IEWSClient        client     = EWSClient.GetEWSClient(mailboxUri, credential);

            ExchangeFolderInfoCollection folders = client.ListPublicFolders();

            foreach (ExchangeFolderInfo publicFolder in folders)
            {
                Console.WriteLine("Name: " + publicFolder.DisplayName);
                Console.WriteLine("Subfolders count: " + publicFolder.ChildFolderCount);
                ListMessagesFromSubFolder(publicFolder, client);
            }
        }
        public override void PopulateFoldersList(ref Repeater repater)
        {
            // Register callback method for SSL validation event
            ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationHandler;

            try
            {
                ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
                string rootUri = client.GetMailboxInfo().RootUri;
                // List all the folders from Exchange server
                ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(rootUri);

                List <MailFolder> foldersList  = new List <MailFolder>();
                List <MailFolder> foldersList2 = new List <MailFolder>();

                AddFolderToList(ref foldersList, ref folderInfoCollection, "inbox");
                AddFolderToList(ref foldersList, ref folderInfoCollection, "drafts");
                AddFolderToList(ref foldersList, ref folderInfoCollection, "sent");
                AddFolderToList(ref foldersList, ref folderInfoCollection, "deleted");
                AddFolderToList(ref foldersList, ref folderInfoCollection, "trash");

                foreach (ExchangeFolderInfo folderInfo in folderInfoCollection)
                {
                    if (folderInfo.DisplayName.Equals("Conversation Action Settings", StringComparison.InvariantCultureIgnoreCase) ||
                        folderInfo.DisplayName.Equals("Quick Step Settings", StringComparison.InvariantCultureIgnoreCase) ||
                        folderInfo.DisplayName.Equals("Contacts", StringComparison.InvariantCultureIgnoreCase) ||
                        folderInfo.DisplayName.Equals("News Feed", StringComparison.InvariantCultureIgnoreCase) ||
                        folderInfo.DisplayName.Equals("Notes", StringComparison.InvariantCultureIgnoreCase) ||
                        folderInfo.DisplayName.Equals("Outbox", StringComparison.InvariantCultureIgnoreCase) ||
                        folderInfo.DisplayName.Equals("Suggested Contacts", StringComparison.InvariantCultureIgnoreCase) ||
                        folderInfo.DisplayName.Equals("Sync Issues", StringComparison.InvariantCultureIgnoreCase) ||
                        folderInfo.DisplayName.Equals("Tasks", StringComparison.InvariantCultureIgnoreCase) ||
                        folderInfo.DisplayName.Equals("Calendar", StringComparison.InvariantCultureIgnoreCase)
                        )
                    {
                        // do not add any of these folder
                    }
                    else
                    {
                        foldersList2.Add(new MailFolder(folderInfo.DisplayName, folderInfo.Uri));
                    }
                }

                foldersList.AddRange(foldersList2);

                repater.DataSource = foldersList;
                repater.DataBind();
            }
            catch (System.Exception) { }
        }
        public static void Run()
        {
            //ExStart: GetFolderTypeInformationUsingEWS
            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:CopyConversations
            IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);

            ExchangeFolderInfoCollection folderInfoCol = client.ListSubFolders(client.MailboxInfo.RootUri);

            foreach (ExchangeFolderInfo folderInfo in folderInfoCol)
            {
                switch (folderInfo.FolderType)
                {
                case ExchangeFolderType.Appointment:
                    // handle Appointment
                    break;

                case ExchangeFolderType.Contact:
                    // handle Contact
                    break;

                case ExchangeFolderType.Task:
                    // handle Task
                    break;

                case ExchangeFolderType.Note:
                    // handle email message
                    break;

                case ExchangeFolderType.StickyNote:
                    // handle StickyNote
                    break;

                case ExchangeFolderType.Journal:
                    // handle Journal
                    break;

                default:
                    break;
                }
                //ExEnd: GetFolderTypeInformationUsingEWS
            }
        }
예제 #9
0
 private static void ListSubFolders(ExchangeClient client, ExchangeFolderInfo folderInfo)
 {
     Console.WriteLine(folderInfo.DisplayName);
     try
     {
         // If this folder has sub-folders, call this method recursively to get messages
         ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(folderInfo.Uri);
         foreach (ExchangeFolderInfo subfolderInfo in folderInfoCollection)
         {
             ListSubFolders(client, subfolderInfo);
         }
     }
     catch (Exception)
     {
     }
 }
 private void AddFolderToList(ref List <MailFolder> foldersList, ref ExchangeFolderInfoCollection folderInfoColl, string folderName)
 {
     try
     {
         var folList = (from obj in folderInfoColl where obj.DisplayName.ToLower().Contains(folderName) select obj);
         if (folList != null)
         {
             var folder = folList.FirstOrDefault();
             if (folder != null)
             {
                 foldersList.Add(new MailFolder(folder.DisplayName, folder.Uri));
                 folderInfoColl.Remove(folder);
             }
         }
     }
     catch (Exception) { }
 }
        private void PopulateFoldersExchangeClient(IEWSClient client, string folderUri, TreeNodeCollection nodes)
        {
            // Get subfolders of the current URI
            ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(folderUri);

            // Add the subfolders to the current tree node
            foreach (ExchangeFolderInfo folderInfo in folderInfoCollection)
            {
                TreeNode node = new TreeNode(folderInfo.DisplayName + "(" + folderInfo.ChildFolderCount + ")", folderInfo.Uri);
                nodes.Add(node);
                // If there are subfolders, call function recursively to add its subfolders
                if (folderInfo.ChildFolderCount > 0)
                {
                    PopulateFoldersExchangeClient(client, folderInfo.Uri, node.ChildNodes);
                }
            }
        }
        public static void Run()
        {
            // ExStart:ExchangeFoldersBackupToPST
            string dataDir = RunExamples.GetDataDir_Exchange();
            // Create instance of IEWSClient class by providing credentials
            const string      mailboxUri = "https://ews.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);

            // Get Exchange mailbox info of other email account
            ExchangeMailboxInfo          mailboxInfo = client.GetMailboxInfo();
            ExchangeFolderInfo           info        = client.GetFolderInfo(mailboxInfo.InboxUri);
            ExchangeFolderInfoCollection fc          = new ExchangeFolderInfoCollection();

            fc.Add(info);
            client.Backup(fc, dataDir + "Backup_out.pst", Aspose.Email.Outlook.Pst.BackupOptions.None);
            // ExEnd:ExchangeFoldersBackupToPST
        }
예제 #13
0
        // Recursive method to get messages from folders and sub-folders
        private static void ListMessagesInFolder(IEWSClient client, ExchangeFolderInfo folderInfo, string rootFolder)
        {
            // Create the folder in disk (same name as on IMAP server)
            string currentFolder = rootFolder + "\\" + folderInfo.DisplayName;

            Directory.CreateDirectory(currentFolder);

            // List messages
            ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(folderInfo.Uri);

            Console.WriteLine("Listing messages....");
            int i = 0;

            foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
            {
                // Get subject and other properties of the message
                Console.WriteLine("Subject: " + msgInfo.Subject);

                // Get rid of characters like ? and :, which should not be included in a file name
                string fileName = msgInfo.Subject.Replace(":", " ").Replace("?", " ");

                MailMessage msg = client.FetchMessage(msgInfo.UniqueUri);
                msg.Save(dataDir + "\\" + fileName + "-" + i + ".msg");

                i++;
            }
            Console.WriteLine("============================\n");
            try
            {
                // If this folder has sub-folders, call this method recursively to get messages
                ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(folderInfo.Uri);
                foreach (ExchangeFolderInfo subfolderInfo in folderInfoCollection)
                {
                    ListMessagesInFolder(client, subfolderInfo, currentFolder);
                }
            }
            catch (Exception)
            {
            }
        }
예제 #14
0
        private static void ListMessagesFromSubFolder(ExchangeFolderInfo publicFolder, IEWSClient client)
        {
            Console.WriteLine("Folder Name: " + publicFolder.DisplayName);
            ExchangeMessageInfoCollection msgInfoCollection = client.ListMessagesFromPublicFolder(publicFolder);

            foreach (ExchangeMessageInfo messageInfo in msgInfoCollection)
            {
                MailMessage msg = client.FetchMessage(messageInfo.UniqueUri);
                Console.WriteLine(msg.Subject);
                msg.Save(dataDir + msg.Subject + ".msg", SaveOptions.DefaultMsgUnicode);
            }

            // Call this method recursively for any subfolders
            if (publicFolder.ChildFolderCount > 0)
            {
                ExchangeFolderInfoCollection subfolders = client.ListSubFolders(publicFolder);
                foreach (ExchangeFolderInfo subfolder in subfolders)
                {
                    ListMessagesFromSubFolder(subfolder, client);
                }
            }
        }
        static void Run()
        {
            // ExStart: PagingSupportForListingFolders
            ///<summary>
            /// This example shows how to retrieve folders information from Exchange Server with Paging Support
            /// Introduced in Aspose.Email for .NET 6.4.0
            ///</summary>
            using (IEWSClient client = EWSClient.GetEWSClient("exchange.domain.com", "username", "password"))
            {
                int itemsPerPage = 5;
                ExchangeFolderInfoCollection totalFoldersCollection = client.ListSubFolders(client.MailboxInfo.RootUri);
                Console.WriteLine(totalFoldersCollection.Count);

                //////////////////// RETREIVING INFORMATION USING PAGING SUPPORT //////////////////////////////////

                List <ExchangeFolderPageInfo> pages = new List <ExchangeFolderPageInfo>();
                ExchangeFolderPageInfo        pagedFoldersCollection = client.ListSubFoldersByPage(client.MailboxInfo.RootUri, itemsPerPage);

                Console.WriteLine(pagedFoldersCollection.TotalCount);

                pages.Add(pagedFoldersCollection);
                while (!pagedFoldersCollection.LastPage)
                {
                    pagedFoldersCollection = client.ListSubFoldersByPage(client.MailboxInfo.RootUri, itemsPerPage, pagedFoldersCollection.PageOffset + 1);
                    pages.Add(pagedFoldersCollection);
                }
                int retrievedFolders = 0;
                foreach (ExchangeFolderPageInfo pageCol in pages)
                {
                    retrievedFolders += pageCol.Items.Count;
                }

                // Verify the total count of folders
                Console.WriteLine(retrievedFolders);
            }
            // ExEnd: PagingSupportForListingFolders
        }
예제 #16
0
        public static void Run()
        {
            using (IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "your.username", "your.Password"))
            {
                try
                {
                    // Create an appointmenta that will be added to secondary calendar folder

                    DateTime date      = DateTime.Now;
                    DateTime startTime = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0);
                    DateTime endTime   = startTime.AddHours(1);

                    string timeZone = "America/New_York";

                    Appointment[] listAppointments;
                    Appointment   appointment = new Appointment("Room 121", startTime, endTime, "*****@*****.**", "*****@*****.**");
                    appointment.SetTimeZone(timeZone);
                    appointment.Summary     = "EMAILNET-35198 - " + Guid.NewGuid().ToString();
                    appointment.Description = "EMAILNET-35198 Ability to add event to Secondary Calendar of Office 365";

                    // Verify that the new folder has been created
                    ExchangeFolderInfoCollection calendarSubFolders = client.ListSubFolders(client.MailboxInfo.CalendarUri);

                    string getfolderName;
                    string setFolderName = "New Calendar";
                    bool   alreadyExits  = false;

                    // Verify that the new folder has been created already exits or not

                    for (int i = 0; i < calendarSubFolders.Count; i++)
                    {
                        getfolderName = calendarSubFolders[i].DisplayName;

                        if (getfolderName.Equals(setFolderName))
                        {
                            alreadyExits = true;
                        }
                    }

                    if (alreadyExits)
                    {
                        Console.WriteLine("Folder Already Exists");
                    }
                    else
                    {
                        // Create new calendar folder
                        client.CreateFolder(client.MailboxInfo.CalendarUri, setFolderName, null, "IPF.Appointment");

                        Console.WriteLine(calendarSubFolders.Count);

                        // Get the created folder URI
                        string newCalendarFolderUri = calendarSubFolders[0].Uri;

                        // appointment api with calendar folder uri
                        // Create
                        client.CreateAppointment(appointment, newCalendarFolderUri);
                        appointment.Location = "Room 122";
                        // update
                        client.UpdateAppointment(appointment, newCalendarFolderUri);
                        // list
                        listAppointments = client.ListAppointments(newCalendarFolderUri);

                        // list default calendar folder
                        listAppointments = client.ListAppointments(client.MailboxInfo.CalendarUri);

                        // Cancel
                        client.CancelAppointment(appointment, newCalendarFolderUri);
                        listAppointments = client.ListAppointments(newCalendarFolderUri);

                        // appointment api with context current calendar folder uri
                        client.CurrentCalendarFolderUri = newCalendarFolderUri;
                        // Create
                        client.CreateAppointment(appointment);
                        appointment.Location = "Room 122";
                        // update
                        client.UpdateAppointment(appointment);
                        // list
                        listAppointments = client.ListAppointments();

                        // list default calendar folder
                        listAppointments = client.ListAppointments(client.MailboxInfo.CalendarUri);

                        // Cancel
                        client.CancelAppointment(appointment);
                        listAppointments = client.ListAppointments();
                    }
                }
                finally
                {
                }
            }
        }