• 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
  • 0
  alpha_omega said:
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.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • The DS925+ which is this years model with 2.5G networking is only marginally more expensive. About £25 more on Amazon UK. Not sure on the certified disks thing though, I guess it depends if the disks they certified are more expensive than the others or not. I use Seagate IronWolfs personally. Are they on the list? I agree with Steven. Synology DSM is miles ahead of the competition, I wouldn't go elsewhere now. The price is justified.
    • Google Cloud announces new Gemini-powered tools to 'increase efficiency' for partners by David Uzondu Google just announced a couple of new AI tools for its Partner Network Hub on Google Cloud, designed to take care of some of the most boring admin work and make things a bit easier for the companies it works with. Putting together a formal Statement of Work can be a tedious process, where every single detail needs to be perfectly aligned with Google Cloud's requirements. The company's new SOW Analyzer, powered by Gemini, tackles this directly. Partners can upload their draft document, and the AI will immediately point out problems like missing clauses or technical goals that are not measurable, even providing examples of how to fix them. In addition to the analyzer, there is a new Bot-Assisted Live Chat. This is an AI agent built into the partner portal that provides 24/7 help with things like onboarding, billing questions, and incentive claims. If the AI cannot solve your problem with billing or rebate claims, it can hand you off to a human agent without making you explain the entire issue from scratch. These two tools are joined by AI-powered updates to the existing Earnings Hub, which is designed to help partners find new growth opportunities by using predictive data to show what services are in demand: The SOW Analyzer and Earnings Hub are available right now for partners in the hub. The Bot-Assisted Live Chat is currently rolling out and is expected to be fully available to all users by next month.
    • Not sure I agree with your particular interpretation of this. An ESU key is still required per device that you have to enter into the device in order to activate ESU. These aren't being given out for free. The linked Microsoft article still states: "If you have paid to enroll your remaining Windows 10 systems in the ESU program..." which seems to confirm this.
    • I swear, whoever is handling the Gundam IP for video games should be fired. How can you go from the gems that were releasing in PS1, PS2 and PS3, to the utter disaster that's today, from the VR game just to be on the hype bandwagon and all the focus on SD. This will probably be studied as one of the worst ways companies mishandle an IP.
  • Recent Achievements

    • Conversation Starter
      Kavin25 earned a badge
      Conversation Starter
    • One Month Later
      Leonard grant earned a badge
      One Month Later
    • Week One Done
      pcdoctorsnet earned a badge
      Week One Done
    • Rising Star
      Phillip0web went up a rank
      Rising Star
    • One Month Later
      Epaminombas earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      535
    2. 2
      ATLien_0
      207
    3. 3
      +FloatingFatMan
      172
    4. 4
      Michael Scrip
      148
    5. 5
      Steven P.
      119
  • Tell a friend

    Love Neowin? Tell a friend!