June 29, 2010

Open An EMail In Outlook

If are running a PC with Outlook and you want to open an email using Outlook from your application (but not send it immediately)
Following sample opens an email dialog with a specified document already attached
private void butEMailFiles_Click(object sender, RoutedEventArgs e)
    string archiveName = GetExistingArchiveName();
    if (File.Exists(archiveName))
        RunShellCommand("Outlook.exe", "/a \"" + archiveName + "\""); 

private static void RunShellCommand(string app, string args)
    string dir = System.IO.Path.GetDirectoryName(app);
    string file = System.IO.Path.GetFileName(app);

    Process process = new Process();
    process.StartInfo.FileName = file;
    process.StartInfo.WorkingDirectory = dir;
    process.StartInfo.Arguments = args;

No comments: