void IAlarmSource.RunThread()
 {
     switch (_configuration.POPIMAP.ToLower())
     {
         case "imap":
             using (
                 _ImapClient =
                 new ImapClient(_configuration.ServerName, _configuration.Port, _configuration.UserName,
                                _configuration.Password, AuthMethod.Login, _configuration.SSL))
             {
                 if (_ImapClient.Supports("IDLE"))
                 {
                     _ImapClient.NewMessage += ImapClientNewMessage;
                 }
                 else
                 {
                     Logger.Instance.LogFormat(LogType.Info, this,
                                               "IMAP IDLE wird vom Server nicht unterstützt!!!");
                 }
                 while (true)
                 {
                     CheckImapMail(_ImapClient);
                     Thread.Sleep(1000);
                 }
             }
     }
 }
Example #2
0
		private void InitializeClient ()
		{
			// Dispose of existing instance, if any.
			if (Client != null)
				Client.Dispose ();
			
			Client = new ImapClient (Server, Port, User, Pass, AuthMethod.Auto);
			if (Client.Authed) {
				Console.ForegroundColor = ConsoleColor.Red;
				Console.WriteLine ("IMAP:: Connected to {0} via Port {1}", Server, Port);
				Console.ForegroundColor = ConsoleColor.White;

				if (Client.Supports ("IDLE") == false) {
					Console.ForegroundColor = ConsoleColor.Red;
					Console.WriteLine ("IMAP:: Server does not support IMAP IDLE");
					Console.ForegroundColor = ConsoleColor.White;
					return;
				}

				// Setup event handlers.
				Client.NewMessage += new EventHandler<IdleMessageEventArgs> (OnNewMessage);

				Client.IdleError += client_IdleError;
			}
		}
Example #3
0
        private void CargarTodos()
        {
            var imap = new ImapClient(
                   config.imap, config.puerto, config.correo, config.pwd, AuthMethod.Auto, true);
              IEnumerable<uint> uids = imap.Search(
                                 SearchCondition.SentSince(DateTime.Now.AddDays(-7)), "inbox"
                               );
              foreach (uint uid in uids) {
            Application.DoEvents();
            Text = uid + "" + uids.Count();
            if (!dataGridView1.IsDisposed) {
              MailMessage m = imap.GetMessage(uid,false);
              DateTime d = Convert.ToDateTime(m.Headers.Get("Date"));
              int indice = dataGridView1.Rows.Add(m.From, m.Subject, d);
              dataGridView1.Rows[indice].Tag = m;
              dataGridView1.Sort(dataGridView1.Columns[2], System.ComponentModel.ListSortDirection.Descending);
            } else {
              break;
            }
              }

              if (imap.Supports("IDLE")) {
            imap.NewMessage += OnNewMessage;
              }
        }
Example #4
0
 public void ReceiveMail()
 {
     try
     {
         string username = AppState.Config.Get("ReceiveMailPlugin.Username", "*****@*****.**");
         string password = AppState.Config.Get("ReceiveMailPlugin.Password", "tnopresenter");
         string server = AppState.Config.Get("ReceiveMailPlugin.Server", "imap.gmail.com");
         int port = AppState.Config.GetInt("ReceiveMailPlugin.Port", 993);
         if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return;
         Client = new ImapClient(server, port, username, password, AuthMethod.Login, true);
         
         // Should ensure IDLE is actually supported by the server
         if (Client.Supports("IDLE") == false)
         {
             Logger.Log("ReceiveMailPlugin", "Server does not support IMAP IDLE", "", Logger.Level.Info);
         }
         else
         {
             // We want to be informed when new messages arrive
             Client.NewMessage += OnNewMessage;
         }
     }
     catch (Exception exception)
     {
         Logger.Log("ReceiveMailPlugin", "Error initializing imap server, check settings", exception.Message,
             Logger.Level.Error);
     }
 }