0

listBox1.Items.Add(from + ": " + x.Subject); 是什么没有返回所需的结果,它添加“:”而不是“FirstNameLastName:主题标题”

https://imapx.codeplex.com/wikipage?title=Sample%20code%20for%20get%20messages%20from%20your%20inbox

https://imapx.codeplex.com/

    List<Task> m = new List<Task>();
    private async void cmdLogin_Click(object sender, EventArgs e)
    {
        bool result = imapMail.Connection();
        if (result)
        {
            result = imapMail.LogIn(email, password);
            if (result)
            {
                var messes = imapMail.Folders[inbox].Messages;
                foreach (var x in messes)
                {
                    string from = "";
                    foreach (var addresses in x.From)
                    {
                        from = addresses.DisplayName;
                    }
                    listBox1.Items.Add(from + ": " + x.Subject);
                }
                foreach (ImapX.Message msgs in imapMail.Folders[inbox].Messages)
                {
                    m.Add(new Task(new Action(() => msgs.Process())));
                }
                await Task.WhenAll(m);

            }
            else { this.Text = "failed login"; }
        }
        else { this.Text = "Failed connection"; }
    }
}

除了冒号之外,这没有返回任何内容,它应该返回一个显示名称:消息主题

4

1 回答 1

0

在您检索消息详细信息(如“来自”、“主题”等)之前,您首先需要对消息调用 Process()。如果您查看ImapX 的源代码,您会看到 Process() 涉及对 IMAP 服务器的服务器调用,以下载消息数据。

看起来您正在尝试在调用 Process() 之前检索发件人地址,这将返回一个空字符串。您需要更改顺序 - 先调用 Process(),然后才能查看消息详细信息。

请参阅下面的代码。我还没有测试过这个。

List<Task> m = new List<Task>();
private async void cmdLogin_Click(object sender, EventArgs e)
{
    bool result = imapMail.Connection();
    if (result)
    {
        result = imapMail.LogIn(email, password);
        if (result)
        {
            foreach (ImapX.Message msgs in imapMail.Folders[inbox].Messages)
            {
                m.Add(new Task(new Action(() => msgs.Process())));
            }
            await Task.WhenAll(m);

            var messes = imapMail.Folders[inbox].Messages;
            foreach (var x in messes)
            {
                string from = "";
                foreach (var addresses in x.From)
                {
                    from = addresses.DisplayName;
                }
                listBox1.Items.Add(from + ": " + x.Subject);
            }
        }
        else { this.Text = "failed login"; }
    }
    else { this.Text = "Failed connection"; }
}
于 2013-07-16T17:10:30.120 回答