public void Mail_holen(Action<Mail> continueWith) { using (var imap = new Imap4Client()) { imap.Connect(mailAccess.Server); imap.Login(mailAccess.Username, mailAccess.Password); var box = imap.SelectMailbox("inbox"); var ids = box.Search("OR (CC @cc.lieser-online.de) (HEADER Envelope-To @cc.lieser-online.de)"); var fetch = box.Fetch; foreach (var id in ids) { var message = fetch.MessageObject(id); var mail = new Mail { Id = id.ToString(), From = message.From.Email, To = message.To.Select(x => x.Email).ToArray(), Cc = message.Cc.Select(x => x.Email).ToArray(), Bcc = message.HeaderFields["Envelope-To"], Subject = message.Subject, Text = message.BodyText.Text }; continueWith(mail); } } continueWith(null); // End-of-Stream signalisieren!! }
static void Main(string[] args) { System.Console.WriteLine("Start work"); string sHostPop = "pop.googlemail.com"; string sHostImap = "imap.googlemail.com"; int nPort = 995; string sUserName = "******"; string sPasword = "theSimpsons"; try { string sEml = @"E:\ut8_encripted_teamlab.eml"; ActiveUp.Net.Mail.Message m = ActiveUp.Net.Mail.Parser.ParseMessageFromFile(sEml); var header = ActiveUp.Net.Mail.Parser.ParseHeader(sEml); Pop3Client pop = new Pop3Client(); // Connect to the pop3 client pop.ConnectSsl(sHostPop, nPort, "recent:" + sUserName, sPasword); if (pop.MessageCount > 0) { ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(4); string sHtml = message.BodyHtml.Text; } else System.Console.WriteLine("No letters!"); pop.Disconnect(); Imap4Client imap = new Imap4Client(); imap.ConnectSsl(sHostImap, 993); imap.Login(sUserName, sPasword); Mailbox inbox = imap.SelectMailbox("inbox"); if (inbox.MessageCount > 0) { ActiveUp.Net.Mail.Message message = inbox.Fetch.MessageObject(6); string sHtml = message.BodyHtml.Text; } imap.Disconnect(); } catch (Exception ex) { System.Console.Write("\r\n" + ex); } System.Console.WriteLine("Stop work"); System.Console.ReadKey(); }
private void _bSearch_Click(object sender, EventArgs e) { // We create Imap client Imap4Client imap = new Imap4Client(); try { // We connect to the imap4 server imap.Connect(_tbImap4Server.Text); this.AddLogEntry(string.Format("Connection to {0} successfully", _tbImap4Server.Text)); // Login to mail box imap.Login(_tbUserName.Text, _tbPassword.Text); this.AddLogEntry(string.Format("Login to {0} successfully", _tbImap4Server.Text)); Mailbox inbox = imap.SelectMailbox("inbox"); // We gets the message matching the search criteria. MessageCollection messages = inbox.SearchParse("searchcritiria"); if (messages.Count > 0) { for (int n = 0; n < messages.Count; n++) { this.AddLogEntry(string.Format("Message ({0}) : {1}", n.ToString(), messages[n].Subject)); } } else { this.AddLogEntry("There is no message using this search pattern"); } } catch (Imap4Exception iex) { this.AddLogEntry(string.Format("Imap4 Error: {0}", iex.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (imap.IsConnected) { imap.Disconnect(); } } }
private void _bRetrieveMessages_Click(object sender, EventArgs e) { // We create Imap client imap = new Imap4Client(); try { // We connect to the imap4 server imap.Connect(_tbImap4Server.Text); this.AddLogEntry(string.Format("Connection to {0} successfully", _tbImap4Server.Text)); // Login to mail box imap.Login(_tbUserName.Text, _tbPassword.Text); this.AddLogEntry(string.Format("Login to {0} successfully", _tbImap4Server.Text)); inbox = imap.SelectMailbox("inbox"); if (inbox.MessageCount > 0) { for (int i = 1; i < inbox.MessageCount + 1; i++) { ActiveUp.Net.Mail.Message message = inbox.Fetch.MessageObject(i); ListViewItem lvi = new ListViewItem(); lvi.Text = i.ToString("0000"); lvi.SubItems.AddRange(new string[] { message.Subject}); lvi.Tag = message; _lvMessages.Items.Add(lvi); this.AddLogEntry(string.Format("{3} Subject: {0} From :{1} Message Body {2}" , message.Subject, message.From.Email, message.BodyText, i.ToString("0000"))); } } else { this.AddLogEntry("There is no unanswered messages in the imap4 account"); } } catch (Imap4Exception iex) { this.AddLogEntry(string.Format("Imap4 Error: {0}", iex.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } }
public void Mail_verschieben(string id, Action onEndOfStream) { if (id == null) { onEndOfStream(); return; } using (var imap = new Imap4Client()) { imap.Connect(mailAccess.Server); imap.Login(mailAccess.Username, mailAccess.Password); var box = imap.SelectMailbox("inbox"); box.MoveMessage(int.Parse(id), "Archiv"); } }
private void _bRetrieveMessage_Click(object sender, EventArgs e) { // We create Imap client Imap4Client imap = new Imap4Client(); try { // We connect to the imap4 server imap.ConnectSsl(_tbImap4Server.Text); this.AddLogEntry(string.Format("Connection to {0} successfully", _tbImap4Server.Text)); // Login to mail box imap.Login(_tbUserName.Text, _tbPassword.Text); this.AddLogEntry(string.Format("Login to {0} successfully", _tbImap4Server.Text)); Mailbox inbox = imap.SelectMailbox("inbox"); if (inbox.MessageCount > 0) { Header header = inbox.Fetch.HeaderObject(1); this.AddLogEntry(string.Format("Subject: {0} From :{1} ", header.Subject, header.From.Email)); } else { this.AddLogEntry("There is no message in the imap4 account"); } } catch (Imap4Exception iex) { this.AddLogEntry(string.Format("Imap4 Error: {0}", iex.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (imap.IsConnected) { imap.Disconnect(); } } }
private void _bEmptyMailbox_Click(object sender, EventArgs e) { // We create Imap client Imap4Client imap = new Imap4Client(); try { // We connect to the imap4 server imap.Connect(_tbImap4Server.Text); this.AddLogEntry(string.Format("Connection to {0} successfully", _tbImap4Server.Text)); // Login to mail box imap.Login(_tbUserName.Text, _tbPassword.Text); this.AddLogEntry(string.Format("Login to {0} successfully", _tbImap4Server.Text)); if (_tbMailboxToEmpty.Text.Length > 0) { Mailbox mailbox = imap.SelectMailbox(_tbMailboxToEmpty.Text); mailbox.Empty(false); this.AddLogEntry(string.Format("Mailbox {0} successfully empty",_tbMailboxToEmpty.Text)); } else { this.AddLogEntry("You have to set a mailbox name to empty"); } } catch (Imap4Exception iex) { this.AddLogEntry(string.Format("Imap4 Error: {0}", iex.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (imap.IsConnected) { imap.Disconnect(); } } }
private void _bRetrieveMessageList_Click(object sender, EventArgs e) { // We create Imap client Imap4Client imap = new Imap4Client(); try { // We connect to the imap4 server imap.Connect(_tbImap4Server.Text); this.AddLogEntry(string.Format("Connection to {0} successfully", _tbImap4Server.Text)); // Login to mail box imap.Login(_tbUserName.Text, _tbPassword.Text); this.AddLogEntry(string.Format("Login to {0} successfully", _tbImap4Server.Text)); Mailbox inbox = imap.SelectMailbox("inbox"); MessageCollection mc = new MessageCollection(); for (int n = 1; n < inbox.MessageCount + 1; n++) { ActiveUp.Net.Mail.Message newMessage = inbox.Fetch.MessageObject(n); mc.Add(newMessage); this.AddLogEntry(string.Format("Message ({0}) : {1}", n.ToString(), newMessage.Subject)); } } catch (Imap4Exception iex) { this.AddLogEntry(string.Format("Imap4 Error: {0}", iex.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (imap.IsConnected) { imap.Disconnect(); } } }
public void Spike() { var mailAccess = MailAccessRepository.LoadFrom("mailfollowup.spikes.mail.access.txt", Assembly.GetExecutingAssembly()); using (var imap = new Imap4Client()) { imap.Connect(mailAccess.Server); imap.Login(mailAccess.Username, mailAccess.Password); var box = imap.SelectMailbox("Archiv"); var ids = box.Search("OR OR (TO @cc.lieser-online.de) (CC @cc.lieser-online.de) (HEADER Envelope-To @cc.lieser-online.de)"); var fetch = box.Fetch; foreach (var id in ids) { var message = fetch.MessageObject(id); Console.WriteLine("{0}: {1}", message.From.Email, message.Subject); //box.MoveMessage(id, "followup"); } } }
private void StartIdleProcess(object sender, DoWorkEventArgs e) { // Get the BackgroundWorker that raised this event. //BackgroundWorker worker = sender as BackgroundWorker; if (imap != null && imap.IsConnected) { imap.StopIdle(); imap.Disconnect(); } imap = new Imap4Client(); imap.NewMessageReceived += new NewMessageReceivedEventHandler(NewMessageReceived); //worker.ReportProgress(1, "Connection..."); imap.Connect(thisForm.imap4ServerTextbox.Text); //worker.ReportProgress(0, "Login..."); imap.Login(thisForm.usernameTextbox.Text, thisForm.passwordTextbox.Text); //worker.ReportProgress(0, "Select 'inbox'..."); imap.SelectMailbox("inbox"); //worker.ReportProgress(0, "Start idle..."); imap.StartIdle(); }
public void MYG_IMAP_READ_AND_MARK_ALWAYS_CONNECT() { int iCountNew = 0; string sNewMsgs = ""; DateTime dtInizio = DateTime.Now; nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Checking; nIcon.Text = "STO CONTROLLANDO LA CASELLA DI POSTA..."; Imap4Client imap = new Imap4Client(); btnRECONNECT.Visible = false; # region CONNECT try { imap = new Imap4Client(); imap.ConnectSsl(SERVER, PORTA); imap.Login(USER, PWD); bIMAP_ERROR = false; } catch (Exception errCONN) { nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Empty_Error; nIcon.Text = "ERRORE CONNESSIONE IMAP:\n" + errCONN.Message; bIMAP_ERROR = true; rtError.Text += DateTime.Now.ToString() + "-> ERRORE CONNESSIONE IMAP:\n" + errCONN.Message + "\n------------------\n"; MGN_ERROR = DateTime.Now.ToString() + "-> ERRORE CONNESSIONE IMAP: " + errCONN.Message; if (MyGNotifier.Properties.Settings.Default.MAIN_AUTO_NOTIFY_ERROR) { if (MyGNotifier.Properties.Settings.Default.MAIN_RAD_NOTIFIER) { RAD_NOTIFY_ERROR(MGN_ERROR); } else { NOTIFY_ERROR(MGN_ERROR); } } } # endregion # region ELABORA MESSAGGI if (!bIMAP_ERROR) { try { imap.Command("capability"); Mailbox inbox = imap.SelectMailbox("inbox"); int[] ids = inbox.Search("UNSEEN"); if (ids.Length > 0) { ActiveUp.Net.Mail.Message msg = null; for (var i = 0; i < ids.Length; i++) { msg = inbox.Fetch.MessageObject(ids[i]); string UNIQUE_ID = msg.Date.ToString() + msg.From.ToString(); if (!MSGS_ID.Contains(UNIQUE_ID)) { iCountNew++; MSGS_ID.Add(UNIQUE_ID); rtLog.Text += DateTime.Now.ToString() + "\n"; rtLog.Text += "DATA: " + msg.Date + "\n"; rtLog.Text += "MITTENTE: " + msg.From + "\n"; rtLog.Text += "OGGETTO: " + msg.Subject + "\n"; rtLog.Text += "----------------------------\n"; sNewMsgs += "DATA: " + msg.Date + "\n"; sNewMsgs += "MITTENTE: " + msg.From + "\n"; sNewMsgs += "OGGETTO: " + msg.Subject + "\n"; sNewMsgs += "---------------------------\n"; } //mark as unread var flags = new FlagCollection(); flags.Add("Seen"); inbox.RemoveFlags(ids[i], flags); } if (iCountNew > 0) { iLastCOUNT = iCountNew; MSGS_DETAILS = sNewMsgs; nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Check; nIcon.Text = iCountNew > 1 ? "SONO PRESENTI " + iCountNew + " NUOVI MESSAGGI" : "E' PRESENTE 1 NUOVO MESSAGGIO!"; bNewMsgICON = true; NEW_MSGS = true; } else { nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Empty_Gray; NEW_MSGS = false; } } else { nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Empty_Gray; NEW_MSGS = false; } } catch (Exception err) { nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Empty_Error; rtError.Text += DateTime.Now.ToString() + "-> ERRORE CONNESSIONE IMAP:\n" + err.Message + "\n------------------\n"; ; MGN_ERROR = DateTime.Now.ToString() + "-> ERRORE ELABORAZIONE IMAP: " + err.Message; if (MyGNotifier.Properties.Settings.Default.MAIN_AUTO_NOTIFY_ERROR) { if (MyGNotifier.Properties.Settings.Default.MAIN_RAD_NOTIFIER) { RAD_NOTIFY_ERROR(MGN_ERROR); } else { NOTIFY_ERROR(MGN_ERROR); } } } } else { rtLog.Text += "\n---------------\n" + DateTime.Now.ToString() + "-> ERRORE CONNESSIONE IMAP!\n---------------\n"; } # endregion # region DISCONNECT try { imap.Disconnect(); } catch (Exception err) { nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Empty_Error; nIcon.Text = "ERRORE DISCONNESSIONE IMAP:\n" + err.Message; rtError.Text += DateTime.Now.ToString() + "-> ERRORE DISCONNESSIONE IMAP:\n" + err.Message + "\n------------------\n"; ; MGN_ERROR = DateTime.Now.ToString() + "-> ERRORE DISCONNESSIONE IMAP: " + err.Message; if (MyGNotifier.Properties.Settings.Default.MAIN_AUTO_NOTIFY_ERROR) { if (MyGNotifier.Properties.Settings.Default.MAIN_RAD_NOTIFIER) { RAD_NOTIFY_ERROR(MGN_ERROR); } else { NOTIFY_ERROR(MGN_ERROR); } } } # endregion if (bNewMsgICON) { nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Check; } else { if (!NEW_MSGS) { nIcon.Text = "NESSUN NUOVO MESSAGGIO!"; } } if (MyGNotifier.Properties.Settings.Default.MAIN_CHECK_MONITOR) { DateTime dtFine = DateTime.Now; TimeSpan ts = dtFine - dtInizio; rtLog.Text += DateTime.Now.ToString() + "-> FINE CONTROLLO CASELLA POSTA: DURATA CONTROLLO " + ts.Seconds.ToString() + " secondi.\n"; } }
public void MYG_IMAP_READ_AND_MARK(Imap4Client imap) { if (!bIMAP_ERROR) { nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Checking; try { imap.Command("capability"); Mailbox inbox = imap.SelectMailbox("inbox"); int[] ids = inbox.Search("UNSEEN"); if (ids.Length > 0) { iCountIDS = 0; for (var i = 0; i < ids.Length; i++) { if (!MSGS_ID.Contains(ids[i].ToString())) { iCountIDS++; MSGS_ID.Add(ids[i].ToString()); } } if (iCountIDS > 0) { iLastCOUNT = iCountIDS; MSGS_DETAILS = ""; nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Check; bNewMsgICON = true; NEW_MSGS = true; //ActiveUp.Net.Mail.Message msg_first = inbox.Fetch.MessageObject(ids[0]); //XElement xmail = new XElement("gmail", // new XAttribute("count", ids.Length.ToString()), // new XAttribute("modified", msg_first.Date.ToString()) //); //string name = "", address = "", from = ""; //Regex reg_name = new Regex("\"[^\"]+"); //Regex reg_address = new Regex("<[^>]+"); ActiveUp.Net.Mail.Message msg = null; for (var i = 0; i < ids.Length; i++) { msg = inbox.Fetch.MessageObject(ids[i]); //from = msg.HeaderFields["from"]; //name = reg_name.Match(from).Value.Replace("\"", ""); //address = reg_address.Match(from).Value.Replace("<", ""); rtLog.Text += DateTime.Now.ToString() + "\n"; rtLog.Text += "DATA: " + msg.Date + "\n"; rtLog.Text += "MITTENTE: " + msg.From + "\n"; rtLog.Text += "OGGETTO: " + msg.Subject + "\n"; rtLog.Text += "----------------------------\n"; MSGS_DETAILS += "DATA: " + msg.Date + "\n"; MSGS_DETAILS += "MITTENTE: " + msg.From + "\n"; MSGS_DETAILS += "OGGETTO: " + msg.Subject + "\n"; MSGS_DETAILS += "---------------------------\n"; //xmail.Add(new XElement("entry", // new XAttribute("id", msg.MessageId), // new XAttribute("modified", msg.Date.ToString()), // new XAttribute("name", name), // new XAttribute("address", address), // new XElement("subject", msg.Subject), // new XElement("body-text", msg.BodyText.TextStripped), // new XElement("body-html", msg.BodyHtml.Text) //)); //mark as unread var flags = new FlagCollection(); flags.Add("Seen"); inbox.RemoveFlags(ids[i], flags); } //File.WriteAllText("gmail.xml", xmail.ToString()); } else { NEW_MSGS = false; nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Empty_Gray; } } else { NEW_MSGS = false; nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Empty_Gray; } } catch (Exception err) { nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Empty_Error; rtError.Text += DateTime.Now.ToString() + "-> ERRORE CONNESSIONE IMAP:\n" + err.Message + "\n------------------\n"; ; MGN_ERROR = DateTime.Now.ToString() + "-> ERRORE ELABORAZIONE IMAP: " + err.Message; if (MGN_ERROR.ToLower().Contains("connessione interrotta")) { CONNECT_IMAP(); } if (MyGNotifier.Properties.Settings.Default.MAIN_AUTO_NOTIFY_ERROR) { NOTIFY_ERROR(MGN_ERROR); } } } else { rtLog.Text += "\n---------------\n" + DateTime.Now.ToString() + "-> ERRORE CONNESSIONE IMAP!\n---------------\n"; } if (bNewMsgICON) { nIcon.Icon = MyGNotifier.Properties.Resources.MyGNotify_Check; } }