你好,我有以下代码,让我在列表视图控件的收件箱中显示电子邮件,并在rtb中显示腐蚀体,我的问题是有更好的方法处理这些数据并显示它比下面的方式我非常新的c#所以详细的答案会很棒
使用chilkat imap组件来处理服务器端 在此先感谢
Chilkat.MessageSet msgSet = imap.Search("ALL", true);
bundle = imap.FetchBundle(msgSet);
Chilkat.Email email;
int i;
for (i = 0; i < bundle.MessageCount - 0; i++)
{
email = bundle.GetEmail(i);
System.Windows.Forms.ListViewItem itmp = new System.Windows.Forms.ListViewItem(email.From);
System.Windows.Forms.ListViewItem.ListViewSubItem itms1 = new System.Windows.Forms.ListViewItem.ListViewSubItem(itmp, email.Subject);
System.Windows.Forms.ListViewItem.ListViewSubItem itms2 = new System.Windows.Forms.ListViewItem.ListViewSubItem(itmp, email.FromName);
itmp.SubItems.Add(itms1);
itmp.SubItems.Add(itms2);
listView1.Items.Add(itmp).Tag = i;
richTextBox1.Text = email.Body;
}
// Save the email to an XML file
bundle.SaveXml("email.xml");
更新了代码
Chilkat.MessageSet msgSet = imap.Search("ALL", true);
bundle = imap.FetchBundle(msgSet);
Chilkat.Email email;
int i;
for (i = 0; i < bundle.MessageCount; i++)
{
email = bundle.GetEmail(i);
string[] row = new string[]{email.From,
email.Subject,email.FromName};
object[] rows = new object[] { row };
foreach (string[] rowArray in rows)
{
listView1.Rows.Add(rowArray);
}
答案 0 :(得分:0)
我认为,你只做了正确的小点
Put a null check for bundle and email object.
for (i = 0; i < bundle.MessageCount - 0; i++) m, why are you substracting 0 from bundle.MessageCount
您的代码很简单,它的目的就是为什么要这样做。