2009-06-16 57 views
0

我試圖通過Gmail帳戶閱讀從一個MOBLE手機獲得正被送往那裏(在郵件正文)的GPS數據(我的手機)錯誤使用C#mail.dll

using (Pop3Client cl = new Pop3Client()) 
      { 
       cl.UserName = "crash893"; 
       cl.Password = "password"; 
       cl.ServerName = "pop.gmail.com"; 
       cl.AuthenticateMode = Pop3AuthenticateMode.Pop; 
       cl.Ssl = true; 
       cl.Authenticate(); 
       ///Get first mail of my mailbox 
       Pop3Message mg = cl.GetMessage(1); <<<<<<<<<< ERROR 
       String MyText = mg.BodyText; 
       ///If the message have one attachment 
       Pop3Content ct = mg.Contents[0]; 
       ///you can save it to local disk 
       ct.DecodeData("c:\\test.txt"); 
      } 

但我得到的郵箱郵件

"Higuchi.Net.Pop3.Pop3ConnectException: Pop3 connection is closed 
at Higuchi.Net.Pop3.Pop3Client.SendCommand(String inCommand) 
at Higuchi.Net.Pop3.Pop3Client.Execute(String inCommand, Boolean inIsMultiLine) 
at Higuchi.Net.Pop3.Pop3Client.Execute(Pop3Command inCommand) 
at Higuchi.Net.Pop3.Pop3Client.GetMessage(Int64 inMailIndex)"} 

理想的「獲得第一個郵件一個例外,我希望做的是開放的這個閱讀該帳戶中的所有新的未讀郵件一定主題行然後閱讀數據在身體上並標記爲已讀

沒有人知道爲什麼它的示數出

沒有任何人有C#郵件任何的遭遇說嘿可以點我在正確的方向進行讀取和makring電子郵件爲已讀等

回答

1
 using (Pop3Client cl = new Pop3Client()) 
     { 
      cl.UserName = "ewgsdssw"; 
      cl.Password = "sdgwsegw"; 
      cl.ServerName = "pop.gmail.com"; 
      cl.AuthenticateMode = Pop3AuthenticateMode.Pop; 
      cl.Port = 995; 
      cl.Ssl = true; 
      cl.Authenticate(); 
      ///Get first mail of my mailbox 
      /// 
      int total = Convert.ToInt16(cl.GetTotalMessageCount()); 

      while (total >= 1) 
      { 
       Pop3Message mg = cl.GetMessage(total); 
       if (mg.Subject == "I am Here") 
       { 

        // http://maps.google.com/maps?q=38.89552,-77.43265 
        //(+/- 76 metres.) 

        string location = mg.BodyText; 
        location = location.Replace("http://maps.google.com/maps?q=","~"); 
        location = location.Replace("metres.)\r\n\r\n","~"); 

        location = location.Split('~')[1]; 

        location = location.Replace("(+/- ", ","); 
        location = location.Replace("\r\n", ""); 


        string[] data = location.Split(','); 
        string lat = data[0]; 
        string lon = data[1]; 
        string res = data[2]; 
        DateTime time = mg.Date; 

        textBox1.AppendText(string.Format("Lat: {0} LON: {1} Res: {2} TIME: {3}\r\n",lat,lon,res,time.ToString())); 

       } 

       total--; 
      } 

     } 
2

這是不可能的標記電子郵件如使用POP協議讀取的。

嘗試使用IMAP。

+0

你確定嗎? outlook如何通過pop3做到這一點? – Crash893 2009-06-16 20:16:09

+0

你有一個易於使用的免費IMAP客戶端? – Crash893 2009-06-16 20:54:20

0

我沒有使用C#Mail的經驗,這個答案可能沒有幫助,但我在嘗試撰寫電子郵件發送/接收相關代碼時遇到了過去的奇怪現象。

原來我們在工作中運行的防病毒軟件有一個允許.EXE的白名單,可以進出POP3或SMTP連接。這是你的問題嗎?