如何使用" $ UID SEARCH ALL"来获取所有消息的消息?

时间:2018-05-07 19:05:50

标签: c# email imap tcpclient

我正在尝试从我的电子邮件中获取所有邮件ID,但它不起作用。我得到了这个答案:

$ BAD [CLIENTBUG] Unrecognised command\r\n\0\0\0\0

如何获得正确答案?

string uids1 = ReceiveResponse("$ SELECT INBOX\r\n");
string uids = ReceiveResponse("$ UID SEARCH ALL" + "\r\n");//query to server

private string ReceiveResponse(string command)
{
    _sb = new StringBuilder();
    try
    {
        if (command != "")
        {
            if (_tcpClient.Connected)
            {
                _dummy = Encoding.ASCII.GetBytes(command);
                _ssl.Write(_dummy, 0, _dummy.Length);
            }
            else
            {
                throw new ApplicationException("TCP CONNECTION DISCONNECTED");
            }
        }
        _ssl.Flush();

        _buffer = new byte[2048];
        _tcpClient.ReceiveTimeout = 20000;

        Encoding iso = Encoding.GetEncoding("ISO-8859-1");

        do
        {
            try
            {
                bytes = _ssl.Read(_buffer, 0, 2048);

                var msg = Encoding.UTF8.GetString(_buffer);

                _sb.Append(msg);
                Thread.Sleep(3);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        } while (_tcpClient.Available > 0);

        string text = _sb.ToString().Replace("\0", string.Empty);

        return _sb.ToString();
    }
    catch (Exception ex)//if we have some problem show message
    {
        throw new ApplicationException(ex.Message);
    }
}

0 个答案:

没有答案