public static void Run() { string dataDir = RunExamples.GetDataDir_IMAP(); // ExStart:ImapClientActivityLogging ImapClient client = new ImapClient("imap.gmail.com", 993, "*****@*****.**", "password"); // Set security mode client.SecurityOptions = SecurityOptions.Auto; try { // Get the message info collection ImapMessageInfoCollection list = client.ListMessages(); // Download each message for (int i = 0; i < list.Count; i++) { // Save the EML file locally client.SaveMessage(list[i].UniqueId, dataDir + list[i].UniqueId + ".eml"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } // ExEnd:ImapClientActivityLogging }
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 { // Select the inbox folder client.SelectFolder(ImapFolderInfo.InBox); // Get the message info collection ImapMessageInfoCollection list = client.ListMessages(); // Download each message for (int i = 0; i < list.Count; i++) { //Save the EML file locally client.SaveMessage(list[i].UniqueId, dataDir + list[i].UniqueId + ".eml"); } //Disconnect to the remote IMAP server client.Disconnect(); } catch (Exception ex) { System.Console.Write(Environment.NewLine + ex.ToString()); } Console.WriteLine(Environment.NewLine + "Downloaded messages from IMAP server."); }
public static void Run() { try { // Connect to the Gmail server ImapClient imap = new ImapClient("imap.gmail.com", 993, "*****@*****.**", "pwd"); // ExStart:SaveGmailMessages // Gets the message info collection and Download each message ImapMessageInfoCollection list = imap.ListMessages(); for (int i = 0; i < list.Count; i++) { // Save the message as an EML file imap.SaveMessage(list[i].UniqueId, list[i].UniqueId + "_out.eml"); } // ExEnd:SaveGmailMessages } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { // The path to the File directory. string dataDir = RunExamples.GetDataDir_IMAP(); // 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:FetchEmailMessagesFromIMAPServer // Select the inbox folder and Get the message info collection client.SelectFolder(ImapFolderInfo.InBox); ImapMessageInfoCollection list = client.ListMessages(); // Download each message for (int i = 0; i < list.Count; i++) { // Save the EML file locally client.SaveMessage(list[i].UniqueId, dataDir + list[i].UniqueId + ".eml"); } // ExEnd:FetchEmailMessagesFromIMAPServer // Disconnect to the remote IMAP server client.Dispose(); } catch (Exception ex) { Console.Write(Environment.NewLine + ex); } }
public static void Run() { // ExStart:MessagesFromIMAPServerToDisk // The path to the File directory. string dataDir = RunExamples.GetDataDir_IMAP(); // 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 { // Select the inbox folder and Get the message info collection client.SelectFolder(ImapFolderInfo.InBox); ImapMessageInfoCollection list = client.ListMessages(); // Download each message for (int i = 0; i < list.Count; i++) { // Save the EML file locally client.SaveMessage(list[i].UniqueId, dataDir + list[i].UniqueId + ".eml"); } // Disconnect to the remote IMAP server client.Dispose(); } catch (Exception ex) { Console.Write(Environment.NewLine + ex); } // ExStart:MessagesFromIMAPServerToDisk Console.WriteLine(Environment.NewLine + "Downloaded messages from IMAP server."); }