[英]Mailkit - Get HTML and Text parts without having full mime message
[英]get text body mailkit
我正在使用 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
}
您可以從客戶那里獲取正文,以同樣的方式獲取摘要。
您可以獲得同步或異步,但使用相同的索引。 我在這里粘貼文檔中的鏈接。 獲取身體部分
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.