// 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: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 }
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 }
// 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); } }
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 }
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:MoveMessageFromOneFolderToAnotherUsingExchangeClient string mailboxURI = "https://Ex2003/exchange/administrator"; // WebDAV string username = "******"; string password = "******"; string domain = "domain.local"; Console.WriteLine("Connecting to Exchange Server...."); NetworkCredential credential = new NetworkCredential(username, password, domain); ExchangeClient client = new ExchangeClient(mailboxURI, credential); 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) { // Nove 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.MoveItems(msgInfo.UniqueUri, client.MailboxInfo.RootUri + "/Processed/" + msgInfo.Subject); Console.WriteLine("Message moved...." + msgInfo.Subject); } else { // Do something else } } // ExEnd:MoveMessageFromOneFolderToAnotherUsingExchangeClient }
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 }
public static void Run() { // ExStart:AccessAnotherMailboxUsingExchangeClient // Create instance of ExchangeClient class by giving credentials ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username", "Username", "password", "domain"); // Get Exchange mailbox info of other email account ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo("*****@*****.**"); // ExEnd:AccessAnotherMailboxUsingExchangeClient }
public static void Run() { // ExStart:AccessAnotherMailboxUsingExchangeWebServiceClient // Create instance of EWSClient class by giving credentials IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); // Get Exchange mailbox info of other email account ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo("*****@*****.**"); // ExEnd:AccessAnotherMailboxUsingExchangeWebServiceClient }
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 override void PopulateFoldersList(ref TreeView tvFolders) { // 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 PopulateFoldersExchangeClient(client, rootUri, tvFolders.Nodes); } catch (System.Exception) { } }
public static void Run() { // ExStart:GetMailboxInformationFromExchangeServer // Create instance of ExchangeClient class by giving credentials ExchangeClient client = new ExchangeClient("https://MachineName/exchange/Username", "Username", "password", "domain"); // Get mailbox size, exchange mailbox info, Mailbox, Inbox folder, Sent Items folder URI , Drafts folder URI Console.WriteLine("Mailbox size: " + client.GetMailboxSize() + " bytes"); ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri); Console.WriteLine("Inbox folder URI: " + mailboxInfo.InboxUri); Console.WriteLine("Sent Items URI: " + mailboxInfo.SentItemsUri); Console.WriteLine("Drafts folder URI: " + mailboxInfo.DraftsUri); // ExEnd:GetMailboxInformationFromExchangeServer }
public static void Run() { // The path to the File directory. // ExStart:GetMailboxInformationFromExchangeWebServices // Create instance of EWSClient class by giving credentials IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); // Get mailbox size, exchange mailbox info, Mailbox and Inbox folder URI Console.WriteLine("Mailbox size: " + client.GetMailboxSize() + " bytes"); ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri); Console.WriteLine("Inbox folder URI: " + mailboxInfo.InboxUri); Console.WriteLine("Sent Items URI: " + mailboxInfo.SentItemsUri); Console.WriteLine("Drafts folder URI: " + mailboxInfo.DraftsUri); // ExEnd:GetMailboxInformationFromExchangeWebServices }
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 }
private void readInbox(ExchangeClient client) { Dictionary <string, clsFileList> convertFiles = new Dictionary <string, clsFileList>(); try { //query mailbox ExchangeMailboxInfo mailbox = client.GetMailboxInfo(); //list messages in the Inbox ExchangeMessageInfoCollection messages = client.ListMessages(mailbox.InboxUri, false); foreach (ExchangeMessageInfo info in messages) { //save the message locally //client.SaveMessage(info.UniqueUri, info.Subject + ".eml"); // create object of type MailMessage MailMessage msg; msg = client.FetchMessage(info.UniqueUri); foreach (Attachment attachedFile in msg.Attachments) { extractAttachment(convertFiles, attachedFile); } // Can't see a 'readed' flag on messages, info or msg // so we'll have to delete emails after we have read them //client.DeleteMessage(info.UniqueUri); } } catch (ExchangeException ex) { // Console.WriteLine(ex.ToString()); } }
public static void Run() { // ExStart:DeleteMessagesFromExchangeServer // Create instance of IEWSClient class by giving credentials string mailboxURI = "https://Ex2003/exchange/administrator"; // WebDAV string username = "******"; string password = "******"; string domain = "domain.local"; Console.WriteLine("Connecting to Exchange Server...."); NetworkCredential credential = new NetworkCredential(username, password, domain); ExchangeClient client = new ExchangeClient(mailboxURI, credential); 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.DeleteMessage(msgInfo.UniqueUri); Console.WriteLine("Message deleted...." + msgInfo.Subject); } else { // Do something else } } // ExEnd:DeleteMessagesFromExchangeServer }
public void ExchangeTest() { /* * string serverAddress = "HY1MAAEX001.HE1.LOCAL"; * string title = "Test"; * string emailAccount = "WindMIData"; * string destinationFolder = @"C:\PipelineData\0.EmailFolder"; */ //string emailPassword = ""; string emailServerType = "EXCHANGE"; //SSL = "Yes"; //port = 993; ExchangeClient client = null; if (emailServerType.ToUpper() == "EXCHANGE") { //client = new ExchangeClient("http://hy1maaex001.he1.local/owa/winmi0", "winmi0", emailPassword, "HE1"); //client = new ExchangeClient("http://hy1maaex001.he1.local/exchange/goldt1", "goldt1", "Hannah321", "HE1"); //client = new ExchangeClient("http://hy1maaex001.he1.local/owa/goldt1", "goldt1", "Hannah321", "HE1"); //https://imail.bpglobal.com/exchange/europeasiarawindata/inbox/ // client = new ExchangeClient("https://imail.bpglobal.com/exchange/europeasiarawindata/inbox", "sheam6", "p", "BP1"); // start String strServerName = "imail.bpglobal.com"; String strDomain = "bp1"; String strUserID = "sheam6"; String strPassword = "******"; //String strUserName = "******"; String strUserName = "******"; String term = "BP"; /* * Console.Write("Server (eg imail.bpglobal.com):"); * strServerName = Console.ReadLine(); * * Console.Write("Domain (eg bp1):"); * strDomain = Console.ReadLine(); * * Console.Write("UserID (eg sheam6):"); * strUserID = Console.ReadLine(); * * Console.Write("Password:"******"Mailbox (eg mike.sheard or europeasiarawindata):"); * strUserName = Console.ReadLine(); * */ // Create our destination URL. String strURL = "https://" + strServerName + "/exchange/" + strUserName + "/InBox"; // was WindData //strURL = "https://imail.bpglobal.com/exchange/europeasiarawindata/InBox/"; // find unread emails string QUERY = "<?xml version=\"1.0\"?>" + "<g:searchrequest xmlns:g=\"DAV:\">" + "<g:sql>SELECT \"urn:schemas:httpmail:subject\", " + "\"urn:schemas:httpmail:from\", \"DAV:displayname\", " + "\"urn:schemas:httpmail:textdescription\" " + "FROM SCOPE('deep traversal of \"" + strURL + "\"') " + "WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False " + "AND \"urn:schemas:httpmail:read\" = False " //+ "AND \"urn:schemas:httpmail:hasattachment\" = False " //+ "\"DAV:hasattachment\"=True " //////////+ "AND \"urn:schemas:httpmail:subject\" LIKE '%" + term + "%' " + "ORDER BY \"urn:schemas:httpmail:date\" DESC" + "</g:sql></g:searchrequest>"; System.Net.HttpWebResponse Response = null; System.IO.Stream RequestStream; System.IO.Stream ResponseStream; System.Xml.XmlDocument ResponseXmlDoc; System.Xml.XmlNodeList SubjectNodeList; System.Xml.XmlNodeList SenderNodeList; System.Xml.XmlNodeList BodyNodeList; System.Xml.XmlNodeList URLNodeList; Console.WriteLine("Mailbox URL: " + strURL); HttpWebRequest Request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strURL); Request.CookieContainer = new CookieContainer(); Request.CookieContainer.Add(AuthenticateSecureOWA(strServerName, strDomain, strUserID, strPassword)); // Ori //Request.Credentials = new System.Net.NetworkCredential( strUserName, strPassword, strDomain); Request.Credentials = new System.Net.NetworkCredential(strUserID, strPassword, strDomain); //Console.WriteLine(String.Format("Got cookies for: {0}\\{1}", strDomain, strUserName)); Console.WriteLine(String.Format("Got cookies for: {0}\\{1}", strDomain, strUserID)); Request.Method = "SEARCH"; Request.ContentType = "text/xml"; Request.KeepAlive = true; Request.AllowAutoRedirect = false; Byte[] bytes = System.Text.Encoding.UTF8.GetBytes(QUERY); Request.Timeout = 30000; Request.ContentLength = bytes.Length; RequestStream = Request.GetRequestStream(); RequestStream.Write(bytes, 0, bytes.Length); RequestStream.Close(); Request.Headers.Add("Translate", "F"); try { Response = (System.Net.HttpWebResponse)Request.GetResponse(); ResponseStream = Response.GetResponseStream(); //' Create the XmlDocument object from the XML response stream. ResponseXmlDoc = new System.Xml.XmlDocument(); ResponseXmlDoc.Load(ResponseStream); SubjectNodeList = ResponseXmlDoc.GetElementsByTagName("d:subject"); SenderNodeList = ResponseXmlDoc.GetElementsByTagName("d:from"); URLNodeList = ResponseXmlDoc.GetElementsByTagName("a:href"); BodyNodeList = ResponseXmlDoc.GetElementsByTagName("d:textdescription"); int i = 1; foreach (XmlElement subject in SubjectNodeList) { Console.WriteLine("WebDav result - Subject: " + subject.InnerText); if (i++ >= 3) { break; // proved our point } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } // read attachment enumAttachments("https://imail.bpglobal.com/exchange/mike.sheard/Inbox/FW:%20Emailing:%20Release.zip.EML", strUserName, strPassword, strDomain); // end // try to read a list of attachments // Working on this bit: GetAttachmentsListXML(strServerName, "https://imail.bpglobal.com/exchange/mike.sheard/WindData/Fuxin%20Data-32.EML", "sheam6", "p", "bp1"); Console.WriteLine("\n\nAspose Test\n\nUsing URL:" + strURL); //client = new ExchangeClient(strURL, strUserName, strPassword, strDomain); // new code goes here client = new ExchangeClient(strURL, strUserID, strPassword, strDomain); client.CookieContainer = new CookieContainer(); client.CookieContainer.Add(AuthenticateSecureOWA(strServerName, strDomain, strUserID, strPassword)); // Aspose client now //client = new ExchangeClient("https://imail.bpglobal.com/exchange/mike.sheard/inbox/", "sheam6", "p", "BP1"); //client = new ExchangeClient("https://imail.bpglobal.com/exchange/mike.sheard/inbox/", Request.Credentials); } try { //query mailbox ExchangeMailboxInfo mailbox = client.GetMailboxInfo(); //list messages in the Inbox ExchangeMessageInfoCollection messages = client.ListMessages(mailbox.InboxUri, false); int i = 1; foreach (ExchangeMessageInfo info in messages) { //save the message locally //client.SaveMessage(info.UniqueUri, info.Subject + ".eml"); Console.WriteLine("Aspose result - subject: " + info.Subject); if (i++ >= 10) { break; // proved our point } } } catch (ExchangeException ex) { Console.WriteLine(ex.ToString()); } finally { Console.ReadLine(); } }