private void AuthenticateImapPlain(Imap4Client imap) { switch (Account.IncomingEncryptionType) { case EncryptionType.StartTLS: _log.Info("IMAP StartTLS connecting to {0}", Account.EMail); imap.ConnectTLS(Account.Server, Account.Port); break; case EncryptionType.SSL: _log.Info("IMAP SSL connecting to {0}", Account.EMail); imap.ConnectSsl(Account.Server, Account.Port); break; case EncryptionType.None: _log.Info("IMAP connecting to {0}", Account.EMail); imap.Connect(Account.Server, Account.Port); break; } _log.Info("IMAP connecting OK {0}", Account.EMail); _log.Info("IMAP logging in to {0}", Account.EMail); if (Account.AuthenticationTypeIn == SaslMechanism.Login) { imap.Login(Account.Account, Account.Password, ""); } else { imap.Authenticate(Account.Account, Account.Password, Account.AuthenticationTypeIn); } _log.Info("IMAP logged in to {0}", Account.EMail); }
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!! }
public void Login(object sender, System.EventArgs e) { try { ActiveUp.Net.Mail.Imap4Client imap4Client = new ActiveUp.Net.Mail.Imap4Client(); imap4Client.Connect((string)Application["server\uFFFD"], System.Convert.ToInt32(Application["port\uFFFD"])); System.Web.Security.FormsAuthentication.SetAuthCookie(iLogin.Text + "|\uFFFD" + iPassword.Text, false); imap4Client.Login(iLogin.Text, iPassword.Text); Session.Add("login\uFFFD", iLogin.Text); Session.Add("imapobject\uFFFD", imap4Client); System.Web.HttpCookie httpCookie = new System.Web.HttpCookie("login\uFFFD", iLogin.Text); System.DateTime dateTime = System.DateTime.Now; httpCookie.Expires = dateTime.AddMonths(2); Response.Cookies.Add(httpCookie); Visible = false; EnableViewState = false; // ((_Default)Page).SetWebmailLanguage(null, null); //BoundMailboxContent.BoundTopNavigation.Enable(); //BoundMailboxContent.BoundTree.LoadTrees(); //BoundMailboxContent.BoundTopNavigation.LoadList(); //BoundMailboxContent.LoadMailbox(Application["startfolder\uFFFD"].ToString(), true); } catch (System.Exception e1) { Visible = true; EnableViewState = true; iLogin.Text = System.String.Empty; // Page.RegisterStartupScript("ShowError\uFFFD", "<script>ShowErrorDialog('\uFFFD" + Language.Get(Server.MapPath("languages/\uFFFD"), Application["defaultlanguage\uFFFD"].ToString()).Words[96].ToString() + "','\uFFFD" + System.Text.RegularExpressions.Regex.Escape(e1.Message + e1.StackTrace).Replace("'\uFFFD", "\\'\uFFFD") + "');</script>\uFFFD"); Page.RegisterStartupScript("ShowError\uFFFD", "<script>ShowErrorDialog('\uFFFD" + Language.Get(Server.MapPath("languages/"), Application["defaultlanguage\uFFFD"].ToString()).Words[96].ToString() + "','\uFFFD" + System.Text.RegularExpressions.Regex.Escape(e1.Message + e1.StackTrace).Replace("'\uFFFD", "\\'\uFFFD") + "');</script>\uFFFD"); } }
/// <summary> /// Gets the imap client. /// </summary> /// <returns>Imap 4 client.</returns> public Imap4Client GetImapClient() { string imapServer = _configurationPropertiesProvider.GetProperty(SettingKeyNames.ImapServer); int imapPort = _configurationPropertiesProvider.GetPropertyInt(SettingKeyNames.ImapPort); // Retrieves the Current User Context UserInformationDto info = _userInformationDtoFactory.CreateUserInformationDto(); // Retrieves the corresponding Staff record for the current user Staff staff = _sessionProvider.GetSession().QueryOver<Staff>().Where(s => s.Key == info.StaffKey).SingleOrDefault(); //string username = "******"; //string password = "******"; string username = null; string password = null; if (staff.DirectAddressCredential.DirectAddress != null) { username = staff.DirectAddressCredential.DirectAddress.Address; password = staff.DirectAddressCredential.DirectAddressPassword; } if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)) { throw new ApplicationException("Username/password are not provided to access IMAP mail server."); } var imap4Client = new Imap4Client(); imap4Client.Connect(imapServer, imapPort, username, password); return imap4Client; }
private void btnClick_Click(object sender, EventArgs e) { Imap4Client client = new Imap4Client(); client.Connect(txtHost.Text, int.Parse(txtPort.Text), txtUser.Text, txtPassword.Text); Imap4Result result = new Imap4Result(); result.Imap = client; result.ShowDialog(); client.Disconnect(); System.Threading.Thread.Sleep(0); }
private static Mailbox Connect(Imap4Client server, string host, int port, string username, string password, string folder, bool useSsl) { if (useSsl) server.ConnectSsl(host, port); else server.Connect(host, port); server.Login(username, password); return server.AllMailboxes.Cast<Mailbox>().First(x => x.Name == folder); }
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.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"); if (inbox.MessageCount > 0) { imap.HeaderRetrieved += new HeaderRetrievedEventHandler(this.HeaderFetched); inbox.Fetch.BeginHeaderObject(1, null); } 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 _bRetrieveAll_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)); //Display all mailbox names on the account. foreach (Mailbox mailbox in imap.Mailboxes) { this.AddLogEntry(string.Format("Mailbox : {0}",mailbox.Name)); } } 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 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 Verbinden() { _imap = new Imap4Client(); _imap.Connect(_config["mailserver_receive"]); _imap.Login(_config["mailserver_user"], _config["mailserver_password"]); }