显示电子邮件的更好方法 c# winforms

发布于 2024-10-06 12:07:47 字数 1700 浏览 5 评论 0原文

你好,我有以下代码,它可以让我在列表视图控件上显示收件箱中的电子邮件,并在 rtb 中显示腐蚀正文我的问题是有没有更好的方法来处理这些数据并显示它,而不是下面的方式我很新c# 如此详细的答案会很棒

ps 我使用 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);
            }

hello i have the following code which lets me display the emails in my inbox on a list view control and display the corrospoding body in a rtb my question is there a better way to handle this data and display it than the way below im pretty new to c# so detailed answers would be great

p.s im using the chilkat imap component to handle the server side if things
Thanks In Advance

  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");

Updated Code

 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);
            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅哥哥的热头脑 2024-10-13 12:07:47

我认为,您只做正确的一小点,

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

您的代码很简单,并且它正在执行其预期的操作,所以为什么要在此时进行更改。

I think , you are doing correct only small point

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

your code is simple and its doing what it is intended to do so why change at this time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文