• 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

    • The Nokia Lumias? Or the third-party HTC One8's? I had HTC's hardware cuz it was slick and reliable... but, yeah, the software left me wanting more and I just couldn't allocate personal time to develop all of the software I would have wanted to see (overworked in other capacities @ MSFT at the time, heh).
    • Microsoft's mobile strategy had great future vision and UX research, but mediocre engineering and inadequate support (third-party and internal business alike). The death knell for WinMo was Google's (mostly YouTube's) incessant API blocking and purposeful release of buggy WinMo builds to force consumers to stay away -- and this was conducted via sabotage of whatever partnerships they were supposed to play nice in. I still yearn for that UI on a modern smartphone...
    • Linux has always been an option but never adopted by the masses despite being free. The reasons are limited usability and features. Despite everything we all complaint about with MS , the overall experience for the general public is much better than what Linux can deliver.
    • If nothing works automatically for you, I'd say pick a better/different distro. Granted, it's trickier with laptops because they use all kinds of weird hardware, but still. I actually just did a fresh Arch Linux install on my netbook, and given that Arch is certainly not an "automagical" distro, I had to do very little manual tweaking, everything but the audio worked out of the box (including plasma and Wayland) and the audio was simply an issue of installing an additional firmware package that wasn't included in the default selection. Which is equivalent of installing additional drivers in Windows. Surely a more user-oriented distro would be even less troublesome (but granted, I haven't used/tested anything outside of Arch for quite some time). And let's not forget that a fair bit of issues that get blamed on Linux (though it also applies to Windows issues) are actually caused by hardware vendors not giving a damn.
    • The reason Linux will never succeed for consumers is simple. There are 800 distro’s and 400 active versions. As a consumer, “I want Linux” - great, which one? No single App Store, and websites will say “use this app, oh, sorry, doesn’t work on yours”. No single place for support, community help is reduced, so many apps don’t work or have compatibility problems. Drivers from manufacturers have issues. The gaming industry isn’t behind it. if you have an old pc, then sure, try Linux, you might love it. But the arguments above don’t stack up.
  • Recent Achievements

    • One Month Later
      POR2GAL4EVER earned a badge
      One Month Later
    • One Year In
      Orpheus13 earned a badge
      One Year In
    • One Month Later
      Orpheus13 earned a badge
      One Month Later
    • Week One Done
      Orpheus13 earned a badge
      Week One Done
    • Week One Done
      serfegyed earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      563
    2. 2
      ATLien_0
      256
    3. 3
      +Edouard
      163
    4. 4
      +FloatingFatMan
      157
    5. 5
      Michael Scrip
      109
  • Tell a friend

    Love Neowin? Tell a friend!