• 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

    • Someone not paying the BBC license at home is a minor inconvenience to BBC. The real problem are these Ai companies STEALING data through scraping and then selling it under their product. Just pirating something for personal use is nowhere near as bad as stealing it to make corporate profits.
    • Vivaldi 7.4.3684.55 is out.
    • Nvidia and Foxconn planning to deploy humanoid robots within months by Paul Hill Never mind intellectual work, Foxconn and Nvidia are now in talks to deploy humanoid robots at Foxconn’s new Houston factory to carry out physical work, Reuters has reported. The two companies want to have the robots operational by the first quarter of 2026. This is a big development for both companies; it marks the first time Nvidia products will be made with robot assistance, and the first time Foxconn has used robots in an AI server factory on a production line. While the development is certainly interesting, and potentially bad for factory workers, we do not know many of the details such as which robots are being planned for use at the factory, what they’ll look like, or how many will be deployed. While Foxconn has trialed robots made by Chinese firm UBTech, the report states that Foxconn is developing its own robots with Nvidia. The news was told to Reuters via unnamed sources who are not allowed to discuss the matter, so they did so under anonymity. They said that the robots will start work early next year and will contribute to the production of Nvidia’s GB300 AI servers. Foxconn has been training the robots to pick and place objects, insert cables, and do assembly work, but it’s not clear exactly what their role will be on the factory floor and whether jobs will be impacted. One of the sources that spoke to Reuters said that the Houston factory was the best place to trial the robots because it is more spacious, giving robots more room to move about. Last month, a Foxconn subsidiary, which is in charge of the group’s AI server business, said there were two robots being developed which are expected to be showcased in November. One of the robots will have legs, while the other will use a wheeled autonomous mobile robot base. Predictably, the latter version will cost less money than the one with legs, but pricing is unknown at this point. Reuters noted that these two businesses are not the only ones working on robots. It also said that Mercedes-Benz and BMW have been testing robots on production lines and that Tesla is developing its own robots too. China is also getting heavily invested in the sector. Jensen Huang, head of Nvidia, believes that they will be in wide use in manufacturing facilities within five years.
    • That's great and all, but humans have a finite range of vision and a rather slow reaction time. I live in a rural area too and the roads are painted with dear carcasses most of the year. It's not because people choose to hit them. A human simply can't react quick enough when they come firing out of the woods perpendicular to your vision. Those issues can and are being solved with machine vision. The industrial world has been doing this for many years already and cars are finally jumping on the bandwagon using the same technology. It's a known fact that driving is the most dangerous thing (most) people do every day, and that's solely because humans are driving. It's one thing to use technology to be lazy, but it's another to use it to be safe and save lives.
    • Microsoft doesn't make AMD drivers. The "AMD" driver on Windows update comes from AMD, its AMD decision to put it there.
  • Recent Achievements

    • First Post
      emptyother earned a badge
      First Post
    • Week One Done
      Crunchy6 earned a badge
      Week One Done
    • One Month Later
      KynanSEIT earned a badge
      One Month Later
    • One Month Later
      gowtham07 earned a badge
      One Month Later
    • Collaborator
      lethalman went up a rank
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      670
    2. 2
      ATLien_0
      273
    3. 3
      Michael Scrip
      218
    4. 4
      +FloatingFatMan
      165
    5. 5
      Steven P.
      163
  • Tell a friend

    Love Neowin? Tell a friend!