public static void Run() { //ExStart:SettingMessageFlags // 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 { Console.WriteLine("Logged in to the IMAP server"); // Mark the message as read and Disconnect to the remote IMAP server client.ChangeMessageFlags(1, ImapMessageFlags.IsRead); client.Dispose(); } catch (Exception ex) { Console.Write(Environment.NewLine + ex); } //ExEnd:SettingMessageFlags Console.WriteLine(Environment.NewLine + "Set message flags from IMAP server."); }
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 { Console.WriteLine("Logged in to the IMAP server"); // ExStart:SettingMessageFlags // Mark the message as read client.ChangeMessageFlags(1, ImapMessageFlags.IsRead); // ExEnd:SettingMessageFlags client.Dispose(); } catch (Exception ex) { Console.Write(Environment.NewLine + ex); } Console.WriteLine(Environment.NewLine + "Set message flags from IMAP server."); }
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 { System.Console.WriteLine("Logged in to the IMAP server"); // Mark the message as read client.ChangeMessageFlags(1, Aspose.Email.Imap.ImapMessageFlags.IsRead); //Disconnect to the remote IMAP server client.Disconnect(); } catch (Exception ex) { System.Console.Write(Environment.NewLine + ex.ToString()); } Console.WriteLine(Environment.NewLine + "Set message flags from IMAP server."); }
private void readInbox(ImapClient client) { Dictionary <string, clsFileList> convertFiles = new Dictionary <string, clsFileList>(); // select the inbox folder client.SelectFolder(ImapFolderInfo.InBox); // get the message info collection ImapMessageInfoCollection list = client.ListMessages(); // iterate through the messages and retrieve one by one // TO DO: this example code might be able to be rewritten as a foreach(ImapMessageInfo... // will still need to do the client.FetchMessage though. for (int i = 1; i <= list.Count; i++) { // create object of type MailMessage MailMessage msg; Utils.WriteToLog(Utils.LogSeverity.Info, processName, String.Format("Reading message number {0} of {1}", i, list.Count)); msg = client.FetchMessage(i); if (!list[i - 1].Readed) { Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Message not read"); foreach (Attachment attachedFile in msg.Attachments) { Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Extracting attachement"); extractAttachment(convertFiles, attachedFile); Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Finished extracting attachement"); //FileStream writeFile = new FileStream(destinationFolder + @"\" + attachedFile.Name, FileMode.Create); //attachedFile.SaveRawContent(writeFile); //writeFile.Close(); //Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Downloaded file: " + destinationFolder + @"\" + attachedFile.Name); //if (immediateExcelExtract == "1" && (attachedFile.Name.ToLower().EndsWith("xls") || attachedFile.Name.ToLower().EndsWith("xlsx"))) //{ // convertFiles.Add(destinationFolder + @"\" + attachedFile.Name, new clsFileList { FullFilePath = destinationFolder + @"\" + attachedFile.Name }); //} } Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Immediate extraction, if required"); //if (immediateExcelExtract == "1") //{ // // In immediate mode we save the contents of each workbook // // to the current folder // // Finally delete all the original xls files // cf.ConvertExcelToCSV(convertFiles, destinationFolder, true); //} Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Changing email status"); client.ChangeMessageFlags(i, Aspose.Network.Imap.MessageFlags.Readed); Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Finished changing email status"); } } }