listBox1.Items.Add的行(来自+“:”+ x.Subject);是什么没有返回所需的结果,它添加“:”而不是“FirstNameLastName:主题标题”
https://imapx.codeplex.com/wikipage?title=Sample%20code%20for%20get%20messages%20from%20your%20inbox
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"; }
}
}
这不会返回除冒号之外的任何内容,它应该返回一个显示名称:消息主题
答案 0 :(得分:0)
在检索邮件详细信息(例如“from”,“subject”等)之前,首先需要在邮件上调用Process()。如果查看source code for ImapX,您会看到Process()涉及对IMAP服务器的服务器调用,以下载消息数据。
看起来你正在尝试在调用Process()之前检索From地址,这将返回一个空字符串。您需要更改订单 - 首先调用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"; }
}