2012-07-01 44 views
0
public class _Variable 
{ 
    public bool MailStat; 
    public Pop3Client pop3; 
    public int lastmailCount; 
    public int currentmailCount; 
    public Message msg; 
    public MessagePart msgPart; 
    public Timer _timer;   
} 

public List<int> _MailReader() 
{ 
    _Variable _var = new _Variable(); 
    try 
    { 
     //HttpContext.Current.Session["Pop3Client"] 

     if (HttpContext.Current.Session["Pop3Client"] == null) 
     { 
      _var.pop3 = new Pop3Client(); 
      _var.pop3.Connect("pop.gmail.com", 995, true); 
      _var.MailStat = _var.pop3.Connected; 
      _var.pop3.Authenticate("[email protected]", "xxxxxxx"); 
      HttpContext.Current.Session["Pop3Client"] = _var.pop3; 
     } 
     else 
     { 
      _var.pop3 = (Pop3Client)HttpContext.Current.Session["Pop3Client"]; 
     } 
     if (_var.MailStat) 
     { 

      //HttpContext.Current.Application["lastmailCount"] = _var.pop3.GetMessageCount(); 
      _var.currentmailCount = _var.pop3.GetMessageCount(); 
      _var.lastmailCount = _global.lastmailCount; 
      if (_var.lastmailCount < _var.currentmailCount) 
      { 
       _global.lastmailCount = _var.currentmailCount; 
       int _diff = _var.currentmailCount - _var.lastmailCount; 
       for (int _loop = _var.currentmailCount; _diff > 0; _diff--) 
       { 
        _var.msg = _var.pop3.GetMessage(_loop-(_diff-1)); 
        _var.msgPart = _var.msg.MessagePart.MessageParts[0]; 
        string bodyPart = _var.msgPart.BodyEncoding.GetString(_var.msgPart.Body).ToString().Trim(); 
        int _result; 
        if (int.TryParse(bodyPart, out _result)) 
        { 
         _global._vbill.Add(Int32.Parse(bodyPart)); 
         _global._vDate.Add(_var.msg.Headers.DateSent.ToString()); 
        } 
       } 
      } 
     } 
     _var.pop3.Dispose(); 
     return _global._vbill; 
    } 
    catch (Exception ex) 
    { 
     return _global._vbill; 
    } 
} 

我正在使用OpenPop.dll,並且在下面的代碼中,即使在我的帳戶中有郵件,pop.getMessageCount也會返回零。GetMessageCount()返回0(零)

_Variable方法包含我在代碼和_MailReader中使用的所有變量。我只是從我的應用程序中讀取所有郵件並返回到列表中,但問題總是零。

+0

的可能重複的[OpenPop - 的Gmail - GetMessageCount()返回0(零)](http://stackoverflow.com/questions/8519656/openpop-gmail-getmessagecount-returns-0-零) –

回答

2

這是Gmail POP3服務器的一項功能。默認情況下,您只能收到未讀郵件。這意味着,如果您或其他人已經下載了某個消息一次,它將不再可能通過pop3協議接收它。

要避免它,你必須配置你的Gmail帳戶。在Gmail的設置的「轉發和POP/IMAP」部分選中「爲所有郵件啓用POP(已下載的事件郵件)」。

截圖:http://i.stack.imgur.com/UE7ip.png