private void OnNewMessage(object sender, NewMessageEventArgs e) { notifyIcon.Visible = true; notifyIcon.ShowBalloonTip(NotifyTimeout, "Вам пришло новое сообщение", e.Message.Subject, ToolTipIcon.Info); UpdateTrayIcon(e.UnreadMails); }
public static void Start() { IC = new ImapClient(Host, Port, Username, Password, AuthMethod.Login, SSL); IsRunning = true; /* Does NOT run in the context of the "UI thread" but in its _own_ thread */ IC.NewMessage += (sender, e) => { MailMessage m = null; int messageCount; lock (IC) { try { m = IC.GetMessage(e.MessageUID, FetchOptions.TextOnly, false); messageCount = IC.Search(SearchCondition.Unseen()).Count(); } catch (IOException) { return; } }; NewMessageEventArgs args = new NewMessageEventArgs(m, messageCount); NewMessageEvent(sender, args); }; }
public static void Start() { bool Gmail = Properties.Settings.Default.UseGmail; string Host = Gmail ? Properties.Settings.Default.GmailImapServer : Properties.Settings.Default.ImapServer; int Port = Gmail ? Int32.Parse(Properties.Settings.Default.GmailServerPort) : Int32.Parse(Properties.Settings.Default.ServerPort); string Username = Properties.Settings.Default.Username; string Password = Encryption.DecryptString(Properties.Settings.Default.Password); bool SSL = Gmail ? true : Properties.Settings.Default.UseSSL; IC = new ImapClient(Host, Port, Username, Password, AuthMethod.Login, SSL); IsRunning = true; /* Does NOT run in the context of the "UI thread" but in its _own_ thread */ IC.NewMessage += (sender, e) => { MailMessage m = null; int messageCount; lock (IC) { m = IC.GetMessage(e.MessageUID, FetchOptions.TextOnly, false); messageCount = IC.Search(SearchCondition.Unseen()).Length; }; NewMessageEventArgs args = new NewMessageEventArgs(m, messageCount); NewMessageEvent(sender, args); }; }
private void OnNewMessage(object sender, NewMessageEventArgs e) { notifyIcon.ShowBalloonTip(300, "You've got new e-mail", e.Message.Subject, ToolTipIcon.Info); if (Properties.Settings.Default.PlaySound) { try { (new SoundPlayer(soundPath)).Play(); } catch (Exception) { } } UpdateTrayIcon(e.UnreadMails); }