简体   繁体   English

获取文本正文邮件包

[英]get text body mailkit

i'm using Mailkit to get the subject of emails , it's working for me but i need to get the text body to , any one could help me any one could help me thanks我正在使用 Mailkit 来获取电子邮件的主题,它对我有用,但我需要将文本正文改为,任何人都可以帮助我任何人都可以帮助我谢谢

async Task FetchMessageSummariesAsync(bool print)
            {
                IList<IMessageSummary> fetched = null;

                do
                {
                    try
                    {
                        // fetch summary information for messages that we don't already have
                        startIndex = startIndex + messages.Count;

                        fetched = client.Inbox.Fetch(startIndex, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId, cancel.Token);
                        break;
                    }
                    catch (ImapProtocolException)
                    {
                        // protocol exceptions often result in the client getting disconnected
                        await ReconnectAsync();
                    }
                    catch (IOException)
                    {
                        // I/O exceptions always result in the client getting disconnected
                        await ReconnectAsync();
                    }
                } while (true);

                messages.Clear();

                foreach (var message in fetched)
                {
                    if (print)
                   Console.WriteLine("new message: {0}", message.Envelope.Subject);

                    messages.Add(message);
                }
                // ---- Insert Data in Database
            }

You can get the body from your client, in the same way, you are getting the summary.您可以从客户那里获取正文,以同样的方式获取摘要。

You can get sync or async, but using the same index.您可以获得同步或异步,但使用相同的索引。 I paste here the link in the documentation.我在这里粘贴文档中的链接。 GetBodyPart 获取身体部分

var items = client.Inbox.Fetch (uids, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure);

foreach (var item in items) {
     // determine a directory to save stuff in
     var directory = Path.Combine (baseDirectory, item.UniqueId.ToString ());

     // create the directory
     Directory.CreateDirectory (directory);

     // IMessageSummary.TextBody is a convenience property that finds the 'text/plain' body part for us
     var bodyPart = item.TextBody;

     // download the 'text/plain' body part
     var body = (TextPart) client.Inbox.GetBodyPart (item.UniqueId, bodyPart);

     // TextPart.Text is a convenience property that decodes the content and converts the result to
     // a string for us
     var text = body.Text;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM