Mimekit / mailkit download message body?

I recently made my own email client and added the receive option, I used mimekit and mailkit as plugins and could download most of my emails to the reader, who should show the content (right now it shows the subject, until, from, date)

How I downloaded the theme to ..., msg.envelope.subject, msg.envelope.to But I can not load the body as follows :( when executing msg.body, msg.textbody, msg.bodyparts, ... they are all lead to NOTHING, the place where it should be is just empty, I can’t get it downloaded :(

Can anybody help me?

+4
source share
1 answer

There are two ways to get the message body:

1.

, , .

:

var message = folder.GetMessage (uid);

var message = folder.GetMessage (index);

UniqueId . Fetch, , , , UniqueId , MessageSummaryItems.UniqueId :

var messages = folder.Fetch (0, -1, MessageSummaryItems.UniqueId |
    MessageSummaryItems.Envelope | ...);

, , .

MessageReader, MimeKit GitHub.

, MimeMessage.

2. ,

, .

, , MessageSummaryItems.BodyStructure Fetch. :

var messages = folder.Fetch (0, -1, MessageSummaryItems.Envelope | 
    MessageSummaryItems.BodyStructure);

(, , , , ).

BodyStructure , msg.Body.

msg.Body BodyPart, . 2 BodyPartMultipart BodyPartBasic. as is, , :

var multipart = msg.Body as BodyPartMultipart;

if (multipart != null) {
    // the top-level body part is a multi-part
} else {
    // the body is a basic singleton part
}

BodyPartMultipart:

foreach (var part in multipart.BodyParts) {
    // each part will either be a BodyPartMultipart
    // or a BodyPartBasic, just like before...
}

2 BodyPartBasic, : BodyPartText BodyPartMessage. A BodyPartText - MIME- ( , MIME- text/*), BodyPartMessage ( MIME message/rfc822).

MIME , , MIME, MIME, .

TextBody HtmlBody IMessageSummary text/plain text/html .

, , , (, , , MIME).

, HTML, HTML MIME ( multipart/related), HtmlBody , .

, , ImapClientDemo MailKit GitHub. MainWindow.cs.

+5
source

Source: https://habr.com/ru/post/1607006/


All Articles