Use .NET send email:
If you want to launch the default mail client to create a new email message, it's really simple and there's plenty of samples available:
System.Diagnostics.Process.Start( "mailto:user@example.com?subject=TestSubject&body=TestBody" );
But what if you just want to launch the client and nothing more? You'll have to read the registry (remember that you need the proper RegistryPermission
for this) to find the default mail client and launch that executable yourself. Here's a method that will do just that:
/// <summary>
/// Launches the default mail client.
/// </summary>
public void LaunchDefaultMailClient()
{
// Open the "HKLM/SOFTWARE/Clients/Mail" key.
Microsoft.Win32.RegistryKey mailKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey( @"SOFTWARE/Clients/Mail" );
// The default mail application is stored in the default value of that key.
string defaultMailApp = (string)mailKey.GetValue( null );
if( defaultMailApp != null && defaultMailApp.Length > 0 )
{
// Open the subkey of the default mail application and the "shell/open/command" key below that.
Microsoft.Win32.RegistryKey cmdKey = mailKey.OpenSubKey( defaultMailApp + @"/shell/open/command" );
// We're now in "HKLM/SOFTWARE/Clients/Mail/<default-mail-app>/shell/open/command".
// The default value of this key is the command line to start.
string command = (string)cmdKey.GetValue( null );
// If there are command arguments, extract them out of the main command string.
string args = string.Empty;
if( command.IndexOf( " " ) > 0 )
{
args = command.Substring( command.IndexOf( " " ) + 1 );
command = command.Substring( 0, command.IndexOf( " " ) );
}
// Start a new process for the mail application.
System.Diagnostics.Process.Start( command, args );
}
}