public NewMailForm(UserData userData, bool isReply, bool isFwd, [Optional] MailInfo originalMail) { InitializeComponent(); mailRepository = new MailRepository("smtp.gmail.com", 465, true, userData); textBoxes = new MetroFramework.Controls.MetroTextBox[] { txtSubject, txtTo, txtNewMail, txtCc, txtBcc }; this.originalMail = originalMail; this.isReply = isReply; this.isFwd = isFwd; }
private void LoadListViewItem(MailInfo email) { loadProgressBar.Maximum = mailRepository.MaxEmails; emailListView.Items.Add(new ListViewItem(new string[] { email.Message.Subject, email.Message.From.ToString(), email.Message.Date.DateTime.ToString() }) { Tag = email }); loadProgressBar.Increment(1); }
public void MarkAsUnRead(MailInfo mail) { using (ImapClient client = new ImapClient()) { client.Connect(mailServer, port, ssl); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(UserData.Email, UserData.Password); IMailFolder folder = client.GetFolder(mail.ParentFolder.FullName); folder.Open(FolderAccess.ReadWrite); folder.RemoveFlags(new List <UniqueId> { mail.Uid }, MessageFlags.Seen, true); folder.Close(); client.Disconnect(true); } }
public MailInfo GetMailById(MailInfo mailInfo) { using (ImapClient client = new ImapClient()) { client.Connect(mailServer, port, ssl); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(UserData.Email, UserData.Password); IMailFolder folder = client.GetFolder(mailInfo.ParentFolder.FullName); folder.Open(FolderAccess.ReadOnly); var results = folder.Search(SearchQuery.Uids(new List <UniqueId> { mailInfo.Uid })); MailInfo message = new MailInfo(folder.GetMessage(results[0]), results[0], folder); client.Disconnect(true); return(message); } }
public void StarEmail(MailInfo mail) { using (ImapClient client = new ImapClient()) { client.Connect(mailServer, port, ssl); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(UserData.Email, UserData.Password); IMailFolder folder = client.GetFolder(mail.ParentFolder.FullName); folder.Open(FolderAccess.ReadWrite); var folders = client.GetFolders(new FolderNamespace('/', "[Gmail]")); foreach (var item in folders) { if (item.FullName.Equals(@"[Gmail]/Csillagozott") || item.FullName.Equals(@"[Gmail]/Starred")) { folder.MoveTo(mail.Uid, client.GetFolder(item.FullName)); } } folder.Close(); client.Disconnect(true); } }
public static List <string> RecieveEmailsIMAP4() { List <string> infosGot = new List <string>(); // Create a folder named "inbox" under current directory // to save the email retrieved. string curpath = Directory.GetCurrentDirectory(); string mailbox = String.Format("{0}\\inboxIMAP4", curpath); // If the folder is not existed, create it. if (!Directory.Exists(mailbox)) { Directory.CreateDirectory(mailbox); } // Gmail IMAP4 server is "imap.gmail.com" MailServer oServer = new MailServer("imap.gmail.com", "*****@*****.**", "Europesbiggestowl", ServerProtocol.Imap4); MailClient oClient = new MailClient("TryIt"); // Set SSL connection, oServer.SSLConnection = true; // Set 993 IMAP4 port oServer.Port = 993; try { // Lookup folder based name. Imap4Folder[] folders = oClient.Imap4Folders; Imap4Folder folder = SearchFolder(oClient.Imap4Folders, "[Gmail]/Trash"); if (folder == null) { throw new Exception("Folder was not found"); } // Select this folder oClient.SelectFolder(folder); oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL); infosGot.Add(info.Index.ToString()); infosGot.Add(info.Size.ToString()); infosGot.Add(info.UIDL.ToString()); // Download email from GMail IMAP4 server Mail oMail = oClient.GetMail(info); infosGot.Add(oMail.From.ToString()); infosGot.Add(oMail.Subject); Console.WriteLine("From: {0}", oMail.From.ToString()); Console.WriteLine("Subject: {0}\r\n", oMail.Subject); // Generate an email file name based on date time. System.DateTime d = System.DateTime.Now; System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-US"); string sdate = d.ToString("yyyyMMddHHmmss", cur); string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i); // Save email to local disk oMail.SaveAs(fileName, true); // Mark email as deleted in GMail account. //oClient.Delete(info); } // Quit and purge emails marked as deleted from Gmail IMAP4 server. oClient.Quit(); } catch (Exception ep) { Console.WriteLine(ep.Message); } return(infosGot); }
public static List <string> RecieveEmailsIMAP4ByFolder() { List <string> infosGot = new List <string>(); // Create a folder named "inbox" under current directory // to store the email file retrieved. string curpath = Directory.GetCurrentDirectory(); string mailbox = String.Format("{0}\\inbox", curpath); // If the folder is not existed, create it. if (!Directory.Exists(mailbox)) { Directory.CreateDirectory(mailbox); } MailServer oServer = new MailServer("imap4.emailarchitect.net", "*****@*****.**", "testpassword", ServerProtocol.Imap4); MailClient oClient = new MailClient("TryIt"); // Set IMAP4 server port oServer.Port = 143; // If your IMAP4 server requires SSL connection, // Please add the following codes: // oServer.SSLConnection = true; // oServer.Port = 993; try { oClient.Connect(oServer); // Lookup folder based name. Imap4Folder folder = SearchFolder(oClient.Imap4Folders, "Deleted Items"); if (folder == null) { throw new Exception("Folder was not found"); } // Select this folder oClient.SelectFolder(folder); // Retrieve emails from selected folder instead of default folder. MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL); infosGot.Add(info.Index.ToString()); infosGot.Add(info.Size.ToString()); infosGot.Add(info.UIDL.ToString()); // Receive email from IMAP4 server Mail oMail = oClient.GetMail(info); infosGot.Add(oMail.From.ToString()); infosGot.Add(oMail.Subject); Console.WriteLine("From: {0}", oMail.From.ToString()); Console.WriteLine("Subject: {0}\r\n", oMail.Subject); // Generate an email file name based on date time. System.DateTime d = System.DateTime.Now; System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-US"); string sdate = d.ToString("yyyyMMddHHmmss", cur); string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i); // Save email to local disk oMail.SaveAs(fileName, true); // Mark email as deleted from IMAP4 server. //oClient.Delete(info); } // Quit and purge emails marked as deleted from IMAP4 server. oClient.Quit(); } catch (Exception ep) { Console.WriteLine(ep.Message); } return(infosGot); }
public static List <String> RecieveEmailsPop3() { List <string> infosGot = new List <string>(); // Create a folder named "inbox" under current directory // to save the email retrieved. string curpath = Directory.GetCurrentDirectory(); string mailbox = String.Format("{0}\\inbox", curpath); // If the folder is not existed, create it. if (!Directory.Exists(mailbox)) { Directory.CreateDirectory(mailbox); } MailServer oServer = new MailServer("pop.gmail.com", "*****@*****.**", "Europesbiggestowl", ServerProtocol.Pop3); MailClient oClient = new MailClient("TryIt"); // If your POP3 server requires SSL connection, // Please add the following codes: oServer.SSLConnection = true; oServer.Port = 995; try { oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; infosGot.Add(info.Index.ToString()); infosGot.Add(info.Size.ToString()); infosGot.Add(info.UIDL.ToString()); Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL); // Receive email from POP3 server Mail oMail = oClient.GetMail(info); infosGot.Add(oMail.From.ToString()); infosGot.Add(oMail.Subject); Console.WriteLine("From: {0}", oMail.From.ToString()); Console.WriteLine("Subject: {0}\r\n", oMail.Subject); // Generate an email file name based on date time. System.DateTime d = System.DateTime.Now; System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-US"); string sdate = d.ToString("yyyyMMddHHmmss", cur); string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i); // Save email to local disk oMail.SaveAs(fileName, true); // Mark email as deleted from POP3 server. oClient.Delete(info); } // Quit and purge emails marked as deleted from POP3 server. oClient.Quit(); } catch (Exception ep) { Console.WriteLine(ep.Message); } return(infosGot); }