电子邮件正文在chilkat邮件中返回空白或null

时间:2019-12-10 04:48:14

标签: chilkat-email

我有以下代码从文件夹中读取一堆电子邮件。它可以使电子邮件正常运行,因为我可以看到电子邮件数量正确并且标头也正确。 但是,它对身体没有任何回报。我也有一封包含简单文本的电子邮件,但是也没有返回任何内容。下面是部分代码。 任何帮助表示赞赏。我正在读取的帐户来自Office 365,并且我使用了imap.Connect (*我可以从Microsoft Outlook中读取这些电子邮件,因此我认为问题出在我的chilkat代码上)

        Chilkat.MessageSet messageSet = imap.Search(@"ALL", fetchUids);
        if (imap.LastMethodSuccess == false)
        {
            txtOutput.Text = txtOutput.Text + Environment.NewLine + imap.LastErrorText;
            return;
        }

        // Fetch the email headers into a bundle object:
        Chilkat.EmailBundle bundle = imap.FetchHeaders(messageSet);
        if (imap.LastMethodSuccess == false)
        {
            txtOutput.Text = txtOutput.Text + Environment.NewLine + imap.LastErrorText;
            return;
        }

        // Sort the email bundle by date, recipient, sender, or subject:
        bool ascending = true ; bool descending = true;
        bundle.SortByDate(ascending);
        //bundle.SortByDate(descending);

        // To sort by recipient, sender, or subject, call 
        // SortBySender, SortByRecipient, or SortBySubject.

        // Display the Subject and From of each email.
        int i = 0;
        string body="";
        while (i < bundle.MessageCount)
        {
            Chilkat.Email email = null;
            email = bundle.GetEmail(i);

            txtOutput.Text = txtOutput.Text + Environment.NewLine + Environment.NewLine + email.GetHeaderField("Date");
            //Debug.WriteLine(email.GetHeaderField("Date"));
            //Debug.WriteLine(email.Subject);
            txtOutput.Text = txtOutput.Text + Environment.NewLine + email.From;
            //Debug.WriteLine(email.From);
            //Debug.WriteLine("--");

            if (email.HasHtmlBody())
            {
                body = email.GetHtmlBody() + String.Empty;
            }
            else if (email.HasPlainTextBody()) 
            {
                body = email.GetPlainTextBody() + String.Empty;
            }
            else
            {
                body = email.Body + String.Empty; 
            }
            txtOutput.Text = txtOutput.Text + Environment.NewLine + body.Trim() ;
            i = i + 1;
        }

1 个答案:

答案 0 :(得分:0)

您下载了仅标头:

Chilkat.EmailBundle bundle = imap.FetchHeaders(messageSet);

当然没有身体...