• 0

[C# .Net] Opening default e-mail client?


Question

8 answers to this question

Recommended Posts

  • 0

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();
  }

  • 0
  dannyres said:
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 by JJ6829
  • 0

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 by JJ6829
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I would not mind paying 120 up to 150 dollars in this economy value of the dollar currency if their video game is quite breathtaking and excellent use of my hard earned work money. I think people need to appreciate all the effort workers and time that goes into excellent and worthy video games. Now if only the publishers and companies behind the video games would share the love with the developers those at the bottom of work making such games happen as in increase their money accounts and give them a more richer life that I wish would have happened . But how companies have bad reputation of being $$$ profit greedy I feel sad if there are any developers that feel unappreciated as in no real compensation for all the hours of work they put into a blockbuster hit . Have a great day everyone . Thank you developers engineers and programmers that make superb video games happen . You have my thanksgiving and I hope you really really appreciate my words . With you all about this
    • I guess they use the free version, which doesn't send money to any Russians.
    • True, you can pin it to the Start Menu, but my preference is to pin it to the Taskbar since I am using W11 on a desktop with a large display and a lot of space on the Taskbar.
    • 200 mph. Try going 200 mph with a vehicle on a street in any city in America. Good luck. Yes its speculation but so is the idea that it has been 100% approved by the government. When a new drug is under development it goes through a number of test phases, each of increasing efficacy and safety. I would imagine it is the same in this case. You can similuate real conditions on test roads with other cars and if successful on test roads you move it to the next test phase of testing it on real streets with human assistance if needed. Testing conditions on test roads can never account for all real life situations on real roads. This is what I imagine is happening now. The final test phase.
  • Recent Achievements

    • Week One Done
      Hartej earned a badge
      Week One Done
    • One Year In
      TsunadeMama earned a badge
      One Year In
    • Week One Done
      shaheen earned a badge
      Week One Done
    • Dedicated
      Cole Multipass earned a badge
      Dedicated
    • Week One Done
      Alexander 001 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      571
    2. 2
      ATLien_0
      186
    3. 3
      +FloatingFatMan
      183
    4. 4
      Skyfrog
      112
    5. 5
      Xenon
      106
  • Tell a friend

    Love Neowin? Tell a friend!