there is a task to get the text from the body of the letter, by what means I don’t try the same result, I get html. I work through Imap. code:
public async static Task PrintImapOne() { List<MimeMessage> messages = await ImapFetchAllMessages(FasadUser.Hostname, FasadUser.Port = 143, FasadUser.SSL, FasadUser.Login, FasadUser.Password); messages.Reverse(); Console.Write(messages.First()); } public static async Task<List<MimeMessage>> ImapFetchAllMessages(String hostname, Int32 port, Boolean useSsl, String username, String password) { using (var client = new ImapClient()) { client.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; List<MimeMessage> allMessages = null; await client.ConnectAsync(hostname, port, useSsl); await client.AuthenticateAsync(username, password); if(client.IsConnected) { if (client.IsAuthenticated) { var inbox = client.Inbox; await inbox.OpenAsync(FolderAccess.ReadOnly); allMessages = new List<MimeMessage>(inbox.Count); foreach (var summary in client.Inbox.Fetch(0, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId).ToList()) { //inbox.GetBodyPart(summary.UniqueId, summary.HtmlBody).ToString(); var message = await inbox.GetMessageAsync(summary.UniqueId); allMessages.Add(message); } } } return allMessages; } } I tried the same thing with Pop3, in general an empty string returns:
async static Task PrintPop3One() { List<MimeMessage> messages = await Pop3FetchAllMessages(FasadUser.Hostname, FasadUser.Port = 110, FasadUser.SSL, FasadUser.Login, FasadUser.Password); messages.Reverse(); Console.Write(messages.First().GetTextBody(TextFormat.Text)); } public static async Task<List<MimeMessage>> Pop3FetchAllMessages(string hostname, int port, bool useSsl, string username, string password) { using (var client = new Pop3Client()) { List<MimeMessage> allMessages = null; await client.ConnectAsync(hostname, port, useSsl); await client.AuthenticateAsync(username, password); if (client.IsConnected) { if (client.IsAuthenticated) { var count = await client.GetMessageCountAsync(); allMessages = new List<MimeMessage>(count); for (int i = 0; i < count; i++) { allMessages.Add(await client.GetMessageAsync(i)); } } } return allMessages; } }
text/plain(plain text). 2.text/html(html letter). So that's the point, if the letter is HTML, then you essentially will not take text from it through MailKit. You can do something likevar body = message.BodyParts.OfType<TextPart>().FirstOrDefault();continue to process the text (body.Text) as you need (for example, disassemble using HAP, ifbody.IsHtml == true). - EvgeniyZ 10:08 pmmessages.First().GetTextBody(TextFormat.Text), and then walk through it using HAP - Yaroslav