I've been reading about various methods of how to do this, but I wanted to ask if something will work or not and was hoping someone could be kind enough to test this out for me.

I do not have an email client (Outlook etc...) and just use Gmail.

If I would like to include a button/link whatever, that a user can click and open their default email client, will this work without importing anything or using some custom class:

        System.Diagnostics.Process.Start("mailto:" + emailTextBox.Text);

when I use that, it opens Gmail on my computer and has a blank message pre-addressed to whatever is in the textbox. Will this work with Outlook or other applications or is it just that since Gmail is web-based it works?

That will not work.
Are you trying to just send a mail message?
...or do you specifically want to start a browser and have it start a mail session or something else?

I'm not trying to "send" an email message, but rather, in a directory of email addresses, when a user clicks the email address or a button, the user's default email client (Outlook, Gmail, Windows Mail, Thunderbird, Netscape Messanger (does that even exist anymore) or whatever...) will open a new email message, or at the very least start the application, and if a new message is created, pre-fill in the "To:" box with the email address they clicked. No message, no subject, no sending, just open, and put the email address in the "To:" field. That's it.

I figured since most computers today have some sort of email client that will open by default when a user clicks an email address in a webpage, I thought that since the HTML for an email link was "mailto:" that if I called that as a process, it would start whatever process handles the "mailto:" protocol.

I guess what I am trying to do is offer the convenience to the user, that if they want to send an email to someone in my application, instead of Copy, Open email, Open new message, Paste in 'To:' field, type message, Send" they can just "Click, type message, send"

If you use a web browser control or a web browser, that will happen naturally.

Use Reference using System.Net.Mail;

  protected void cmdSend_Click(object sender, EventArgs e)
    {

        try
        {
            MailMessage message = new MailMessage();

            message.From = new MailAddress("from@domain.com");
            message.To.Add(new MailAddress("to@domain.com"));

            message.Subject = "Subject";
            message.Body = "Body of the message"; 

            SmtpClient client = new SmtpClient();
            client.Send(message);

        }
        catch (Exception ex)
        {
            //...
        }

    }

*** A web.config file must contain information about SMTP access as shown below.***

<system.net>
  <mailSettings>
     <smtp from="from@domain.com">
       <network host="mail.doimain.com" port="587" userName="from@domain.com" password="password"/>
     </smtp>
  </mailSettings>
</system.net>

No no, I don't think you understand what I'm trying to do.

It's not a web program, it's a WinForms program and I don't want to create and send an email message. All I want to do is if the user clicks a button my application will tell the operating system to open the default email program with a new message addressed to a certain person.

This has to be an option somehow, considering you can "register" with the operating system a default email client. Assuming that you can set a default client, that must mean that there has to be a way for other applications to tell the operating system "Hey, open the default email program" and the OS can do that even though the application asking the OS to do that has no idea what application that is.

So, assuming the command the OS gets to open the default email client is "open email client" if my application tells the OS to do that on a computer with Outlook 2007 installed and set as the default email client, that is the program that will open, and if it's Thunderbird that will open...etc...

I don't want to send it, just open it.

Try something like:

string command = "mailto:test@test.com?subject=Test Subject&body=Line 1%0D%0ALine 2";
Process.Start(command);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.