• 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

    • Minecraft Chase the Skies update and Vibrant Visuals graphics overhaul lands next week by Pulasthi Ariyasinghe The second major game update of the year for Minecraft is almost here. Mojang today announced that its next Game Drop, Chase the Skies, is landing on June 17. Alongside it, the highly anticipated graphics overhaul, dubbed Vibrant Visuals, will be available too, making the day a rather big occasion for Minecraft fans. The Chase the Skies update has a large number of gameplay features and content, but one of the biggest is the expansion of the Ghast. Now, players will be able to find Happy Ghasts as a tameable mob, letting up to five players ride them on journeys across the skies. To get one, players will have to find small, dehydrated Ghasts near fossil structures in the Nether, then bring it to the overworld and feed it plenty of water. It is also possible to craft dried Ghasts from Nether materials. Other features of this update include a handy player locator bar, better leads functionality, craftable saddles, a new music disc, and more. As for the Vibrant Visuals upgrade, Mojang is touting a visual refresh that lets players witness how lights and shadows affect the Minecraft world. "Fly high with your happy ghast to watch the sunrise reflect on the rippling ocean, make art with shifting shadows, descend into dark depths, or simply sit back and enjoy the vivid beauty of each biome," says the studio. "With updated in-game visuals you’ll see how light and shadow transform the Overworld – water reflects, forests become shaded, fog drifts, and waterfalls glimmer in the light." The currently supported devices for Vibrant Visuals include Xbox Series X|S, Xbox One, PlayStation 4, PlayStation 5, PC, as well as Android (Android: Adreno 640, Mali-G68, Mali-G77, or Xclipse 530 or higher) and iOS (A12 or M1 or higher.)   Unfortunately, the Vibrant Visuals upgrade will only be available on the Bedrock Edition of Minecraft, at least for now. Mojang has said that it plans to bring the visual overhaul to the Java Edition of Minecraft at a later date, but no information or release window has been announced just yet.
    • Once people get use to the square-ish case, they'll probably switch the display to square as well.
    • Why would you think it's not enabled all the time? Because they said so?
    • $100 billion of the $200 billion is in N.Y. State over the upcoming 20 years plus. Obviously 20+ year spending plans are subject to change.
    • I own one somewhere and even got the email from Amazon letting me know about the recall but not sure I'll be able to find it. Haven't seen it in months.
  • 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
      549
    2. 2
      ATLien_0
      250
    3. 3
      +Edouard
      163
    4. 4
      +FloatingFatMan
      157
    5. 5
      Michael Scrip
      110
  • Tell a friend

    Love Neowin? Tell a friend!