Hey guys i'm trying to figure out how to open a new message window from outlook when i click a button on my form any help greatly aprreciated thanks.

Recommended Answers

All 4 Replies

Try the following:

Application objOutlook = new ApplicationClass();
            NameSpace objNS = objOutlook.GetNamespace("MAPI");

            MailItem objmail = (MailItem)objOutlook.CreateItem(OlItemType.olMailItem);
            objmail.To = "sample.email@domain.com;
            objmail.BCC = "bcc@domain.com";
            objmail.CC = "cc@domain.com";
            objmail.Subject = "Subject of the email goes here";
            objmail.Body = "Body of the email goes here...";

You dont have to use all the above mentioned attributes (To, BCC, CC, body etc) if you dont want to.
You would also have to include the Microsoft Office Libraries. Right click on the project on visual studio, select 'Add Reference'
Select 'COM' tab
Scroll down to 'Microsoft Office 12 Object Library and add it.
Add Microsoft Outlook Object Library as well.

and make sure you include the following as well:

using Microsoft.Office.Interop.Outlook;

before using the above mentioned code.

You can also use the mailto: extension to open up the default email client:

private void button1_Click(object sender, EventArgs e)
    {
      string to = "test@gmail.com; test2@gmail.com";
      string subject = "test subject";
      string body = "test body";
      MailTo(to, subject, body);
    }

    public static void MailTo(string To, string Subject, string Body)
    {
      StringBuilder sb = new StringBuilder();
      sb.Append("mailto:" + To);
      sb.Append("&subject=" + Subject);
      sb.Append("?body=" + Body);
      System.Diagnostics.Process.Start(sb.ToString());
    }
1.private void button1_Click(object sender, EventArgs e)2.    {3.      string to = "test@gmail.com; test2@gmail.com";4.      string subject = "test subject";5.      string body = "test body";6.      MailTo(to, subject, body);7.    }8.9.    public static void MailTo(string To, string Subject, string Body)10.    {11.      StringBuilder sb = new StringBuilder();12.      sb.Append("mailto:" + To);13.      sb.Append("&subject=" + Subject);14.      sb.Append("?body=" + Body);15.      System.Diagnostics.Process.Start(sb.ToString());16.    } 

above code is fine but how to add CC mail

commented: Please don't bump a 3 year old thread. Start your own if you have a question. -2

mailto:user@mail.com&cc=copy@mail.com&subject=mySubject?body=blaaaaaaaaaaaa

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.