Guest Dan C Posted July 29, 2004 Share Posted July 29, 2004 How do I open the default e-mail client from a form in C# ? I just want it to load the client, not create a new message window. Link to comment Share on other sites More sharing options...
0 Andareed Posted July 29, 2004 Share Posted July 29, 2004 This reg key contains everything you need to know: HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail Their is an easier way using MAPI directly, but I don't know how to do this from C#. Link to comment Share on other sites More sharing options...
0 lexecutil Posted July 29, 2004 Share Posted July 29, 2004 Not trying to take over your thread of anything.. but do you know how to open the default Internet browser aswell? Dan Link to comment Share on other sites More sharing options...
0 jonovate Posted July 29, 2004 Share Posted July 29, 2004 I just figured it out while googling for VB (since everything is usually done in VB); Anyways (for email): 1. Add a Reference to the COM object (COM tab) "Microsoft MAPI Controls 6.0". 2. I tested it with just adding a button to a form. Two ways to do it. using MSMAPI; ......... private void button1_Click(object sender, System.EventArgs e) { MAPISessionClass ms = new MAPISessionClass(); ms.SignOn(); } or (if u don't like using a lot of namespaces): private void button1_Click(object sender, System.EventArgs e) { MSMAPI.MAPISessionClass ms = new MSMAPI.MAPISessionClass(); ms.SignOn(); } Link to comment Share on other sites More sharing options...
0 jonovate Posted July 29, 2004 Share Posted July 29, 2004 (edited) Not trying to take over your thread of anything.. but do you know how to open the default Internet browser aswell?Dan The following works, i just thought of a new idea, will edit in a bit. System.Diagnostics.Process.Start("address"); //edit// Just figured out how to run it if u want it just to open default web browser, like clicking on the icon (pretend a button2 on your form is the icon, etc): ......... using Microsoft.Win32; using System.Diagnostics; ......... ... ......... private void button2_Click(object sender, System.EventArgs e) { string sDefaultWeb = Registry.ClassesRoot.OpenSubKey("http").OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command").GetValue("").ToString(); int iLoc = sDefaultWeb.IndexOf("-url"); sDefaultWeb = (sDefaultWeb.Remove(iLoc, sDefaultWeb.Length - iLoc)).Trim(); Process.Start(sDefaultWeb); } Edited July 29, 2004 by JJ6829 Link to comment Share on other sites More sharing options...
0 jonovate Posted July 29, 2004 Share Posted July 29, 2004 (edited) It's not letting me edit my above reply for some reason ( i only see Report and Quote where the edit button should be). So here's an updated version. Tested with IE, Firefox, and Mozilla (above version was customized for Mozilla/firefox): ..... using Microsoft.Win32; using System.Diagnostics; ... .... private void button2_Click(object sender, System.EventArgs e) { //reads the default web application from registry, and removes any command line parameters string sDefaultWeb = Registry.ClassesRoot.OpenSubKey("http").OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command").GetValue("").ToString().ToLower(); int iLoc = sDefaultWeb.IndexOf(".exe") + 4; sDefaultWeb = (sDefaultWeb.Remove(iLoc, sDefaultWeb.Length - iLoc)); //Fixes the IE default browser glitch if( sDefaultWeb[0] == 34 ) sDefaultWeb = sDefaultWeb.Remove(0, 1); //start process Process.Start(sDefaultWeb); } //edit: i guess u could do Andareed's way too with the above code for both ways (MAPI is easier like he said for mail). U just gotta understand the Registry class otherwise Edited July 29, 2004 by JJ6829 Link to comment Share on other sites More sharing options...
0 Guest Dan C Posted July 29, 2004 Share Posted July 29, 2004 Thanks alot Andareed and JJ6829. I will try them out :) Thanks alot again guys! Link to comment Share on other sites More sharing options...
0 alpha_omega Posted July 30, 2004 Share Posted July 30, 2004 You can do it all in one line: System.Diagnostics.Process.Start("mailto:".ToString() + "asd@asd.com"); Link to comment Share on other sites More sharing options...
0 jonovate Posted July 31, 2004 Share Posted July 31, 2004 You can do it all in one line:System.Diagnostics.Process.Start("mailto:".ToString() + "asd@asd.com"); Yes but if you knew how to read a thread fully, you would see he wanted to launch the program, not open a new message window. Link to comment Share on other sites More sharing options...
Question
Guest Dan C
How do I open the default e-mail client from a form in C# ? I just want it to load the client, not create a new message window.
Link to comment
Share on other sites
8 answers to this question
Recommended Posts