我正在使用 C# 阅读来自我的网络域的电子邮件并使用 OpenPop.net 库。
它正在阅读电子邮件,但它只收到新的电子邮件。我想让它像 hotmail 一样,它应该同时获取已读和未读,然后使用 CSS 我会以不同的方式显示它们。请指导我如何做到这一点。
谢谢
POP3 不是像 IMAP 那样的存储系统。
当您从 POP3 收到邮件时,它通常会从服务器中删除电子邮件(永远)。这就是它的工作原理。
也许 OpenPOP 中有一个选项,允许在检索后不删除服务器上的电子邮件。
编辑:
我猜您正在尝试使用他们的 POP3 从 gmail 检索邮件。Gmail 有一些奇怪的非标准 POP3 行为。Gmail 将隐藏已检索的邮件并忽略 POP3 DELE 命令。有关此行为的更多信息,请参阅此相关问题。
Openpop 示例之一显示了如何检索所有消息:
/// <summary>
/// Example showing:
/// - how to fetch all messages from a POP3 server
/// </summary>
/// <param name="hostname">Hostname of the server. For example: pop3.live.com</param>
/// <param name="port">Host port to connect to. Normally: 110 for plain POP3, 995 for SSL POP3</param>
/// <param name="useSsl">Whether or not to use SSL to connect to server</param>
/// <param name="username">Username of the user on the server</param>
/// <param name="password">Password of the user on the server</param>
/// <returns>All Messages on the POP3 server</returns>
public static List<Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password)
{
// The client disconnects from the server when being disposed
using(Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(hostname, port, useSsl);
// Authenticate ourselves towards the server
client.Authenticate(username, password);
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
// We want to download all messages
List<Message> allMessages = new List<Message>(messageCount);
// Messages are numbered in the interval: [1, messageCount]
// Ergo: message numbers are 1-based.
for(int i = 1; i <= messageCount; i++)
{
allMessages.Add(client.GetMessage(i));
}
// Now return the fetched messages
return allMessages;
}
}
因为 POP 标准行为是:
而 IMAP 标准行为是:
鉴于您的 POP 库足够低级,您始终可以更改该行为。
您可以做的是在从 smtp 服务器获取所有电子邮件时将它们写入数据库,因此下次打开应用程序时,您仍然可以阅读所有电子邮件。
通常邮件服务器会在客户端收到邮件时删除邮件(在 Outlook 和其他邮件客户端中,有一个特定的设置可以打开/关闭此功能,也许 OpenPop lib 也有此设置)