• 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

    • There's a few here upset Kamala Harris never got the Presidency! lol....
    • Yeah, he identified a whole lot of wasteful spending of US taxpayer money. What's wrong with that? Nothing, unless you had your fingers in the pie of course.
    • How to reduce the annoying Liquid Glass effects on iOS 26 by Aditya Tiwari Apple announced Liquid Glass at WWDC 2025 in all of its glory. It's a new glass-inspired design language from the iPhone-maker making its way to most of its software platforms, including iOS 26, iPadOS 26, macOS 26, tvOS 26, and watchOS 26. Apple markets Liquid Glass as a new translucent material that "behaves like glass in the real world. Its color is informed by surrounding content and intelligently adapts between light and dark environments." The Cupertino giant isn't wrong. The new glass-inspired design does bring a fresh coat of paint and some beautiful visuals to the iPhone and other Apple-made devices. However, as the dust from the mega arrival settles, people are starting to realize the current drawbacks of having too much glass on their device. There have been reports of users, including those at Neowin, experiencing readability issues, background separation issues, and trouble focusing on the content displayed on the screen due to its transparent nature. While these are small nuances on Apple's part that can be fixed without much hassle, it's degrading the initial experience of what the company calls its biggest visual upgrade since iOS 7. That said, there are some workarounds built into iOS 26 that will help you tone down the shortcomings. If you're running the iOS 25 Developer Beta 1 on your supported iPhone model, you can follow these steps to make things a little better: Go to the Settings app on your iPhone. Scroll down and tap on Accessibility > Display & Text Size. Next, you'll find two toggle options: Reduce Transparency and Increase Contrast. When you enable the Reduce Transparency toggle button, iOS 26 can "improve contrast by reducing transparency and blurs on some backgrounds to increase legibility." The other toggle, Increase Contrast, does what its name suggests. It can "increase color contrast between app foreground and background colors." Enabling each of these toggle buttons individually or simultaneously will have different effects on your iPhone's user interface. Control Center is being criticized for the extra transparency, making the UI look cluttered and difficult to focus. Here, the Reduce Transparency button adds a darker background to make the Control Center UI elements stand out. Liquid Glass transparency issues are also prevalent in the Notification Center and the navigation controls of various apps. In the image above, see how the text of the navigation buttons has become unreadable or hard to focus on with certain backgrounds. It's challenging to determine what can trigger such behavior, as one can have countless color combinations on their device. In the image below, this is how these buttons look when both Reduce Transparency and Increase Contrast are enabled. It's still a hit or miss depending on what colors you are dealing with. Part of the blame also goes to the fact that iOS 26 is still an early beta, and the change doesn't render as intended every time. You can also notice the difference in the look and feel of the Control Center when reduced transparency is turned on. On a side note, you can add the Reduce Transparency and Increase Contrast buttons in the Control Center for quicker access. That said, let's wait to see what changes Apple will implement as it continues to gather feedback through the beta program. Hopefully, the software will become more stable when the first public beta of iOS 26 arrives sometime in July. Interested users can try out the latest iPhone update through the developer beta program, noting that early builds might come with unexpected bugs and issues.
    • Austin residents rally against Tesla's robotaxi launch by Hamid Ganji Tesla's plan to launch its robotaxi service in Austin, Texas, has sparked protests in the city. While the EV maker targets June 22 as the launch date, local residents are raising their voices against the plan due to political disagreements and safety concerns. As reported by CNBC, public safety advocates and political protesters are organizing protests against Tesla's robotaxi launch in Austin. Members of the Dawn Project, Tesla Takedown, and Resist Austin have cited safety issues with Tesla's automated driving systems. Meanwhile, Elon Musk's involvement in Donald Trump's administration and his work in the Department of Government Efficiency (DOGE) has prompted another group of people to join the Austin protests against Tesla. To show Austin citizens the safety problems of Tesla's self-driving system, The Dawn Project brought a Tesla Model Y to the protest, equipped with the company's Full Self-Driving (FSD) software (version 13.2.9). In the demonstration, the Model Y with FSD software reportedly zoomed past a school bus with a stop sign held out and ran over a child-sized mannequin placed in front of the car. The FSD package includes automatic lane-keeping, steering, and parking. It is unclear to what extent this test was conducted under standard conditions or what Tesla's defense is. However, multiple cases of Tesla FSD software malfunction in the past have resulted in collisions or severe accidents, according to data collected by National Highway Traffic Safety Administration. Interestingly, The Dawn Project CEO Dan O'Dowd is the CEO of another company that sells embedded safety and security solutions to carmakers like Ford and Toyota. It remains to be seen whether Tesla could launch a robotaxi service in Austin despite the residents' protests. Earlier this week, Elon Musk demonstrated the new version of Tesla's FSD software in a post on X. Musk's decisions on DOGE fuel public backlash against Tesla. While Musk left the Trump administration after a beef with the president, he's still a target of public criticism, which directly imapcts Tesla. As a result, the slow sales have even caused Tesla to sell its Cybertruck with 0 percent APR to boost sales.
    • I'm sure Denmark would stand to lose a lot if US consumers stopped buying Danish products, whether that's Lurpak butter or hi-fi equipment.
  • Recent Achievements

    • One Month Later
      greege earned a badge
      One Month Later
    • Week One Done
      greege earned a badge
      Week One Done
    • Week One Done
      LagFighterZ earned a badge
      Week One Done
    • First Post
      ThatGuyOnline earned a badge
      First Post
    • One Month Later
      5i3zi1 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      547
    2. 2
      ATLien_0
      229
    3. 3
      +FloatingFatMan
      166
    4. 4
      Michael Scrip
      119
    5. 5
      +Edouard
      91
  • Tell a friend

    Love Neowin? Tell a friend!