Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / C#
Tip/Trick

Get Default Mail Client Name

Rate me:
Please Sign up or sign in to vote.
2.80/5 (2 votes)
8 Jun 2011CPOL 26.6K   3   6
How to get the default mail client name.
Here is the code:
C#
public string getDefaultMailClient()
{
  try
  {
      object mailClient = Registry.GetValue(
        @"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail", "", "none");
      return mailClient.ToString();
  }
  catch (Exception exGetDefaultMailClient)
  {
      Util.EscribirLog(exGetDefaultMailClient.Message);
      return "Outlook Express";
  }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer gmSoft
Argentina Argentina
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Comments and Discussions

 
GeneralIn Alternate 1, hkey returns a string ¨mailto\shell\open\com... Pin
Salam Y. ELIAS21-Jun-11 8:20
professionalSalam Y. ELIAS21-Jun-11 8:20 
GeneralReason for my vote of 3 Agreed with the others who have comm... Pin
Ed Nutting14-Jun-11 9:15
Ed Nutting14-Jun-11 9:15 
GeneralReason for my vote of 2 Nice short how to but needs to be dr... Pin
NetSecurity14-Jun-11 2:40
NetSecurity14-Jun-11 2:40 
GeneralAgree with nbgangsta. Update your code. Pin
thatraja10-Jun-11 17:01
professionalthatraja10-Jun-11 17:01 
GeneralBetter yet; just throw an exception. If it's unable to find ... Pin
JV99998-Jun-11 21:43
professionalJV99998-Jun-11 21:43 
Better yet; just throw an exception. If it's unable to find a default mail client it should fail, because it's sole purpose is to determine the default mail client.

So I would make it:

public string getDefaultMailClient()
{
try
{
object mailClient = Registry.GetValue(
@"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail", "", "none");
return mailClient.ToString();
}
catch (Exception exGetDefaultMailClient)
{
Util.EscribirLog(exGetDefaultMailClient.Message);
throw new Exception("Unable to determine default mail client", ex);
}
}
GeneralYou're returning Outlook Express if you're unsuccessful? Are... Pin
Groulien8-Jun-11 21:07
Groulien8-Jun-11 21:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.