protected override void OnDispose() { try { if (!m_pClient.IsDisposed && m_pClient.IsConnected) { m_pClient.WriteLine("QUIT"); m_pClient.Disconnect(); } } catch (Exception ex) { string dummy = ex.Message; } m_pClient.Dispose(); }
/// <summary> /// Connects to the specified LumiSoft mail server. /// </summary> /// <param name="host">Host name or IP of server to connect.</param> /// <param name="userName">User name.</param> /// <param name="password">Password.</param> public void Connect(string host, string userName, string password) { if (m_Connected) { return; } m_pClient.Connect(host, 5252); // Read greeting text string response = ReadLine(); if (!response.StartsWith("+OK")) { m_pClient.Disconnect(); throw new Exception(response); } // Auth user m_pClient.TcpStream.WriteLine("LOGIN " + TextUtils.QuoteString(userName) + " " + TextUtils.QuoteString(password)); response = ReadLine(); if (!response.StartsWith("+OK")) { m_pClient.Disconnect(); throw new Exception(response); } m_Connected = true; m_Host = host; m_UserName = userName; m_pTimerNoop = new Timer(30000); m_pTimerNoop.AutoReset = true; m_pTimerNoop.Elapsed += new ElapsedEventHandler(m_pTimerNoop_Elapsed); m_pTimerNoop.Enabled = true; }
/// <summary> /// 断开连接 /// </summary> /// <param name="ErrorDescription"></param> /// <returns></returns> public bool DisConnect(ref string ErrorDescription) { ErrorDescription = ""; if (!tcpClient.IsConnected) { return(true); } try { tcpClient.Disconnect(); return(true); } catch (Exception e) { ErrorDescription = e.Message; return(false); } }