public static void Run() { //ExStart:1 // The path to the File directory. string dataDir = RunExamples.GetDataDir_IMAP(); // Create an instance of the ImapClient class ImapClient imapClient = new ImapClient(); // Specify host, username and password, and set port for your client imapClient.Host = "imap.gmail.com"; imapClient.Username = "******"; imapClient.Password = "******"; imapClient.Port = 993; imapClient.SecurityOptions = SecurityOptions.Auto; imapClient.UseMultiConnection = MultiConnectionMode.Enable; ImapMailboxInfo mailboxInfo = imapClient.MailboxInfo; ImapFolderInfo info = imapClient.GetFolderInfo(mailboxInfo.Inbox.Name); ImapFolderInfoCollection infos = new ImapFolderInfoCollection(); infos.Add(info); imapClient.Backup(infos, dataDir + @"\ImapBackup.pst", BackupOptions.Recursive); //ExEnd:1 }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_IMAP(); string dstEmail = dataDir + "1234.eml"; //Create an instance of the ImapClient class ImapClient client = new ImapClient(); //Specify host, username and password for your client client.Host = "imap.gmail.com"; // Set username client.Username = "******"; // Set password client.Password = "******"; // Set the port to 993. This is the SSL port of IMAP server client.Port = 993; // Enable SSL client.SecurityOptions = SecurityOptions.Auto; try { // Get all folders in the currently subscribed folder Aspose.Email.Imap.ImapFolderInfoCollection folderInfoColl = client.ListFolders(); // Iterate through the collection to get folder info one by one foreach (Aspose.Email.Imap.ImapFolderInfo folderInfo in folderInfoColl) { // Folder name Console.WriteLine("Folder name is " + folderInfo.Name); ImapFolderInfo folderExtInfo = client.ListFolder(folderInfo.Name); // New messages in the folder Console.WriteLine("New message count: " + folderExtInfo.NewMessageCount); // Check whether its readonly Console.WriteLine("Is it readonly? " + folderExtInfo.ReadOnly); // Total number of messages Console.WriteLine("Total number of messages " + folderExtInfo.TotalMessageCount); } //Disconnect to the remote IMAP server client.Disconnect(); } catch (Exception ex) { System.Console.Write(Environment.NewLine + ex.ToString()); } Console.WriteLine(Environment.NewLine + "Getting folders information from IMAP server."); }
/// <summary> /// Recursive method to get messages from folders and sub-folders /// </summary> /// <param name="folderInfo"></param> /// <param name="rootFolder"></param> private static void ListMessagesInFolder(ImapFolderInfo folderInfo, string rootFolder, ImapClient client) { // Create the folder in disk (same name as on IMAP server) string currentFolder = Path.Combine(Path.GetFullPath("../../../Data/"), folderInfo.Name); Directory.CreateDirectory(currentFolder); // Read the messages from the current folder, if it is selectable if (folderInfo.Selectable == true) { // Send status command to get folder info ImapFolderInfo folderInfoStatus = client.ListFolder(folderInfo.Name); Console.WriteLine(folderInfoStatus.Name + " folder selected. New messages: " + folderInfoStatus.NewMessageCount + ", Total messages: " + folderInfoStatus.TotalMessageCount); // Select the current folder client.SelectFolder(folderInfo.Name); // List messages ImapMessageInfoCollection msgInfoColl = client.ListMessages(); Console.WriteLine("Listing messages...."); foreach (ImapMessageInfo msgInfo in msgInfoColl) { // Get subject and other properties of the message Console.WriteLine("Subject: " + msgInfo.Subject); Console.WriteLine("Read: " + msgInfo.IsRead + ", Recent: " + msgInfo.Recent + ", Answered: " + msgInfo.Answered); // Get rid of characters like ? and :, which should not be included in a file name string fileName = msgInfo.Subject.Replace(":", " ").Replace("?", " "); // Save the message in MSG format MailMessage msg = client.FetchMessage(msgInfo.SequenceNumber); msg.Save(currentFolder + "\\" + fileName + "-" + msgInfo.SequenceNumber + ".msg", Aspose.Email.Mail.SaveOptions.DefaultMsgUnicode); } Console.WriteLine("============================\n"); } else { Console.WriteLine(folderInfo.Name + " is not selectable."); } try { // If this folder has sub-folders, call this method recursively to get messages ImapFolderInfoCollection folderInfoCollection = client.ListFolders(folderInfo.Name); foreach (ImapFolderInfo subfolderInfo in folderInfoCollection) { ListMessagesInFolder(subfolderInfo, rootFolder, client); } } catch (Exception) { } }
public static void Run() { // Create an instance of the ImapClient class ImapClient client = new ImapClient(); // Specify host, username, password, Port and SecurityOptions for your client client.Host = "imap.gmail.com"; client.Username = "******"; client.Password = "******"; client.Port = 993; client.SecurityOptions = SecurityOptions.Auto; try { // ExStart:GettingFoldersInformation // Get all folders in the currently subscribed folder ImapFolderInfoCollection folderInfoColl = client.ListFolders(); // Iterate through the collection to get folder info one by one foreach (ImapFolderInfo folderInfo in folderInfoColl) { // Folder name and get New messages in the folder Console.WriteLine("Folder name is " + folderInfo.Name); ImapFolderInfo folderExtInfo = client.GetFolderInfo(folderInfo.Name); Console.WriteLine("New message count: " + folderExtInfo.NewMessageCount); Console.WriteLine("Is it readonly? " + folderExtInfo.ReadOnly); Console.WriteLine("Total number of messages " + folderExtInfo.TotalMessageCount); } // ExEnd:GettingFoldersInformation // Disconnect to the remote IMAP server client.Dispose(); } catch (Exception ex) { Console.Write(Environment.NewLine + ex); } Console.WriteLine(Environment.NewLine + "Getting folders information from IMAP server."); }
public override int ListMessagesInFolder(ref GridView gridView, string folderUri, string searchText) { try { Email.MailQuery mQuery = Common.GetMailQuery(searchText); ImapFolderInfo folderInfoStatus = client.ListFolder(folderUri); client.SelectFolder(folderUri); ImapMessageInfoCollection msgInfoColl = null; if (mQuery == null) { msgInfoColl = client.ListMessages(Common.MaxNumberOfMessages); } else { msgInfoColl = client.ListMessages(mQuery, Common.MaxNumberOfMessages); } List <Message> messagesList = new List <Message>(); messagesList = (from msg in msgInfoColl orderby msg.Date descending select new Message() { UniqueUri = msg.UniqueId, Date = Common.FormatDate(msg.Date), Subject = Common.FormatSubject(msg.Subject), From = Common.FormatSender(msg.From) }).ToList(); gridView.DataSource = messagesList; gridView.DataBind(); return(msgInfoColl.Count); } catch (Exception) { } return(0); }