如何在C#中使用IMAP进行电子邮件解析时将未读电子邮件显示为粗体 [英] How to show unread email as bold in email parsing using IMAP in C#

查看:109
本文介绍了如何在C#中使用IMAP进行电子邮件解析时将未读电子邮件显示为粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用IMAP协议在C#中进行EMAIL解析

以粗体格式显示未读电子邮件或消息的任何方法或其他方式



提前致谢



我尝试过:



Hi,
I am doing EMAIL parsing in C# using IMAP Protocol
Any Method or other way to show the unread email or message in Bold Format

Thanks in Advance

What I have tried:

private void ReceiveMails()
		{
			// Disable buttons while working
			connectAndRetrieveButton.Enabled = false;
			uidlButton.Enabled = false;
			progressBar.Value = 0;

			try
			{
				if (pop3Client.Connected)
					pop3Client.Disconnect();
				pop3Client.Connect(popServerTextBox.Text, int.Parse(portTextBox.Text), useSslCheckBox.Checked);
				pop3Client.Authenticate(loginTextBox.Text, passwordTextBox.Text);
				int count = pop3Client.GetMessageCount();
				totalMessagesTextBox.Text = count.ToString();
				messageTextBox.Text = "";
				messages.Clear();
				listMessages.Nodes.Clear();
				listAttachments.Nodes.Clear();

				int success = 0;
				int fail = 0;
				for (int i = count; i >= 1; i -= 1)
				{
					// Check if the form is closed while we are working. If so, abort
					if (IsDisposed)
						return;

					// Refresh the form while fetching emails
					// This will fix the "Application is not responding" problem
					Application.DoEvents();

					try
					{
						Message message = pop3Client.GetMessage(i);

						// Add the message to the dictionary from the messageNumber to the Message
						messages.Add(i, message);

						// Create a TreeNode tree that mimics the Message hierarchy
						TreeNode node = new TreeNodeBuilder().VisitMessage(message);

						// Set the Tag property to the messageNumber
						// We can use this to find the Message again later
						node.Tag = i;

						// Show the built node in our list of messages
						listMessages.Nodes.Add(node);

						success++;
					} catch (Exception e)
					{
						DefaultLogger.Log.LogError(
							"TestForm: Message fetching failed: " + e.Message + "\r\n"+
							"Stack trace:\r\n" +
							e.StackTrace);
						fail++;
					}

					progressBar.Value = (int)(((double)(count-i)/count) * 100);
				}

				MessageBox.Show(this, "Mail received!\nSuccesses: " + success + "\nFailed: " + fail, "Message fetching done");

				if(fail > 0)
				{
					MessageBox.Show(this,
					                "Since some of the emails were not parsed correctly (exceptions were thrown)\r\n" +
					                "please consider sending your log file to the developer for fixing.\r\n" +
					                "If you are able to include any extra information, please do so.",
					                "Help improve OpenPop!");
				}
			} catch (InvalidLoginException)
			{
				MessageBox.Show(this, "The server did not accept the user credentials!", "POP3 Server Authentication");
			} catch (PopServerNotFoundException)
			{
				MessageBox.Show(this, "The server could not be found", "POP3 Retrieval");
			} catch(PopServerLockedException)
			{
				MessageBox.Show(this, "The mailbox is locked. It might be in use or under maintenance. Are you connected elsewhere?", "POP3 Account Locked");
			} catch (LoginDelayException)
			{
				MessageBox.Show(this, "Login not allowed. Server enforces delay between logins. Have you connected recently?", "POP3 Account Login Delay");
			} catch (Exception e)
			{
				MessageBox.Show(this, "Error occurred retrieving mail. " + e.Message, "POP3 Retrieval");
			} finally
			{
				// Enable the buttons again
				connectAndRetrieveButton.Enabled = true;
				uidlButton.Enabled = true;
				progressBar.Value = 100;
			}
		}

推荐答案

您显示的代码不是IMAP - 它建议您使用POP,这是不可能的,因为你希望



我建议你看看Mailkit& IMAP,那么你可以做类似的事情。



The code you have shown isnt IMAP - it suggests you are using POP, with which its impossible to do as you wish

I'd suggest you look at Mailkit & IMAP, then you can do something like

foreach (var uid in folder.Search (SearchQuery.NotSeen)) {
    var message = folder.GetMessage (uid);
}





获取'看不见'的消息



to get 'unseen' messages


这篇关于如何在C#中使用IMAP进行电子邮件解析时将未读电子邮件显示为粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆