Reputation: 117
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
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
}
Upvotes: 3
Views: 7346
Reputation: 328
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;
}
Upvotes: 2