Diese Methode ermittelt die Anzahl der ungelesenen Mails.
Getestet habe ich diese Methode mit Outlook Express.
benötigte Namespaces:
Microsoft.Win32
/// <summary>
/// Gets the number of unread mail.
/// </summary>
/// <param name="emailadress">The emailadress.</param>
/// <returns>the number of unread mail</returns>
private static int GetUnreadMailCount(string emailadress)
{
int count = 0;
string unreadkey = String.Format("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\UnreadMail\\{0}", emailadress);
if (!SubKeyExist(unreadkey))
throw new Exception("Subkey does not exist!");
else
{
RegistryKey myKey = Registry.CurrentUser.OpenSubKey(unreadkey);
count = Convert.ToInt32(myKey.GetValue("MessageCount"));
}
return count;
}
/// <summary>
/// Check if the subkey exist.
/// </summary>
/// <param name="Subkey">The subkey.</param>
/// <returns>true or false</returns>
private static bool SubKeyExist(string Subkey)
{
RegistryKey myKey = Registry.CurrentUser.OpenSubKey(Subkey);
return myKey != null;
}
1 Kommentare zum Snippet