2011-09-08 6 views
1

私はGmailアカウントからメールを読んでいます..私はログインしようとしましたが成功しました..しかし、受信トレイからメールを受け取ることができません.. 以下のコードです私はログインに使用されています...asp.netのgmailアカウントからメールを読む

try 
     { 

      TcpClient tcpclient = new TcpClient(); // create an instance of TcpClient 
      tcpclient.Connect("pop.gmail.com", 995); // HOST NAME POP SERVER and gmail uses port number 995 for POP 
      System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream()); // This is Secure Stream // opened the connection between client and POP Server 
      sslstream.AuthenticateAsClient("pop.gmail.com"); // authenticate as client 
      //bool flag = sslstream.IsAuthenticated; // check flag 
      System.IO.StreamWriter sw = new StreamWriter(sslstream); // Asssigned the writer to stream 
      System.IO.StreamReader reader = new StreamReader(sslstream); // Assigned reader to stream 
      sw.WriteLine("[email protected]"); // refer POP rfc command, there very few around 6-9 command 
      sw.Flush(); // sent to server 
      sw.WriteLine("password"); 
      sw.Flush(); 
      sw.WriteLine("RETR 1"); // this will retrive your first email 
      sw.Flush(); 
      sw.WriteLine("Quit "); // close the connection 
      sw.Flush(); 
      string str = string.Empty; 
      string strTemp = string.Empty; 
      while ((strTemp = reader.ReadLine()) != null) 
      { 
       if (strTemp == ".") // find the . character in line 
       { 

        break; 
       } 

       if (strTemp.IndexOf("-ERR") != -1) 
       { 
        break; 
       } 
       str += strTemp; 
      } 
      Response.Write(str); 
      Response.Write("" + "Congratulation.. ....!!! You read your first gmail email "); 
     } 
     catch (Exception ex) 
     { 
      Response.Write(ex.Message); 
     } 

誰でも私はどのように受信ボックスから実際のメールを取得することができます教えてください。

答えて

0
  1. あなたはできるだけ早くあなたがコマンドを発行すると、サーバーの応答をお読みください。
  2. あなたは成功したGmailにログインしていない - あなたはPOP3電子メールが "-ERR" テキスト
  3. STR + = strTempが含まれている場合PASS
  4. あなたのコードが失敗し、USERのようなコマンドを使用する必要があります。大きな添付ファイルを使用して電子メールを復活させるときにあなたのアプリを殺すつもりです

私はホイールを改造しないことをお勧めします - POP3アクセス用のライブラリがあります。

1

あなたはMail.netを見たことがありますか?私はそれを自分で使う必要はありませんでしたが、ここでは良いことを書いています。

乾杯