Feedback

Anzahl ungelesener Emails ermitteln

Sprache: C#

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;
}
/// <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 Kommentar

  1. Mit Thunderbird 3.0 geht das. Outlook 2010 hat den Schlüssel bei mir nicht gesetzt. Braucht das bestimmte Voraussetzungen?