+1 vote
foreach (MessageInfo info in infos) {

    dt.Rows.Add();
    dt.Rows[dtMessages.Rows.Count - 1]["From"]
            = info.Envelope.Sender.Address;
    dt.Rows[dtMessages.Rows.Count - 1]["Subject"]
             = info.Envelope.Subject;
    dt.Rows[dtMessages.Rows.Count - 1]["DateSent"]
             = info.Envelope.Date;
    dt.Rows[dtMessages.Rows.Count - 1]["body"]
             = 

what should i do?

by

1 Answer

0 votes

With Imap's GetMessageInfoByUID you only download most common email properties (e.g. from, to, subject, message structure).

You are not downloading body (text or html), and attachments.

You need to use Imap.GetMessageByUID - this downloads entire email, including attachments.

Alternatively you may use MessageInfo.BodyStructure.Text or/and MessageInfo.BodyStructure.Html and then Imap.GetTextByUID:

BodyStructure structure = info.BodyStructure;

// Download only text and html parts
string text, html;

if (structure.Text != null)
    text = imap.GetTextByUID(structure.Text);

if (structure.Html != null)
    html = imap.GetTextByUID(structure.Html);

You can find more details in this article:
https://www.limilabs.com/blog/download-parts-of-email-message

by (301k points)
edited by
I'm getting error in initializing bodystructure
...