2012-07-01 49 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