GetMessageCount()返回0(零) [英] GetMessageCount() returns 0 (zero)

查看:788
本文介绍了GetMessageCount()返回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("nithin.testing1@gmail.com", "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并在接下来的code pop.getMessageCount将返回零,即使有在我的帐户的邮件。

I am using the OpenPop.dll and In the following code pop.getMessageCount is returning zero even there are mails in my account.

_variable方法包含了我在code和_MailReader使用的所有变量。我只是从我的应用程序读取我的所有邮件,并返回到一个列表,但是这就是问题所在计数为零始终。

_Variable method contains all the variables I used in the code and in _MailReader. I am just reading all my mails from my application and returning into a list but this is the problem count is zero always.

推荐答案

这是Gmail的POP3服务器的功能。默认情况下,您只能接收未读邮件。这意味着,如果你或其他人已经下载了某些消息一次,也不会是可能通过POP3协议接收它了。

It's a feature of gmail pop3 server. By default, you can receive only unread messages. That means, if you or somebody else already has downloaded certain message once, it will not be possible to receive it by pop3 protocol anymore.

要避免它,您必须配置您的Gmail帐户。检查的所有邮件(包括已经下载的邮件事件)启用POP中的转发和POP / IMAPGmail设置的部分。

To avoid it, you have to configure your gmail account. Check "Enable POP for all mail (event mail that's already been downloaded)" in "Forwarding and POP/IMAP" section of gmail settings.

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

这篇关于GetMessageCount()返回0(零)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆