0

hotmailアカウントに接続して未読メールをチェックするWindowsテストアプリを作成しました。現在、アプリを使用して、hotmailアカウントから最後のメールを取得しています。

最新のメールを取得する方法と、SSLStream オブジェクトを使用して最新のメールの件名と本文を取得できるかどうかを教えてください。

「最初のメールを取得する」と書かれている場所は、最初のメールの合計バイト数しか取得していません。助けてください。最初のメールの件名と本文を取得します。

        TcpClient mail = new TcpClient();
        SslStream sslStream;
        int bytes = -1;
        mail.Connect("pop3.live.com", 995);
        sslStream = new SslStream(mail.GetStream());
        sslStream.AuthenticateAsClient("pop3.live.com");

        byte[] buffer = new byte[2048];
        // Read the stream to make sure we are connected
        bytes = sslStream.Read(buffer, 0, buffer.Length);
        string message = Encoding.ASCII.GetString(buffer, 0, bytes);
        MessageBox.Show(message);

        //Send the users login details
        sslStream.Write(Encoding.ASCII.GetBytes("USER user_name\r\n"));
        bytes = sslStream.Read(buffer, 0, buffer.Length);
        string message1 = Encoding.ASCII.GetString(buffer, 0, bytes);
        MessageBox.Show(message1);

        //Send the password                        
        sslStream.Write(Encoding.ASCII.GetBytes("PASS password\r\n"));
        bytes = sslStream.Read(buffer, 0, buffer.Length);
        string message2 = Encoding.ASCII.GetString(buffer, 0, bytes);
        MessageBox.Show(message2);

        // Get the first email 
        sslStream.Write(Encoding.ASCII.GetBytes("RETR 1\r\n"));
        bytes = sslStream.Read(buffer, 0, buffer.Length);
        string message4 = Encoding.ASCII.GetString(buffer, 0, bytes);
        MessageBox.Show(message4);

        string str = string.Empty;
        string strTemp = string.Empty;
        StreamReader reader = new StreamReader(sslStream); 
        while ((strTemp = reader.ReadLine()) != null)
        {

            // find the . character in line
            if (strTemp == ".")
            {
                break;

            }
            if (strTemp.IndexOf("-ERR") != -1)
            {
                break;

            }
            str += strTemp;

        }
        MessageBox.Show(str);
    }

コードをいくつか変更すると、hotmail アカウントにアクセスできます。ただし、AOl アカウントにアクセスしようとすると、同じコードを使用します。IO 例外が発生します。このコードを使用して AOL メール システムに接続する方法を教えてください。助けてくれてありがとう。

4

1 に答える 1

0

pop サーバーのメールを取得するには、pop プロトコルを実装する必要があると思います。あなたの場合、ホットメール。ここで、hotmail/gmail などの pop3 サーバーからのメールを開くことについての良い記事を見つけることができます。

于 2012-05-02T09:50:17.640 に答える