Search code examples
c#winformsoutlookcarbon-copy

Microsoft Outlook adding cc to email


I currently have existing code that automates and email and sends files. I now need to add a cc. I have looked all over, but can't seem to find out with my existing code. Any help would be greatly appreciated. Thank you.

         private void button13_Click(object sender, EventArgs e)
    {
        //Send Routing and Drawing to Dan
        // Create the Outlook application by using inline initialization. 
        Outlook.Application oApp = new Outlook.Application();
        //Create the new message by using the simplest approach. 
        Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
        //Add a recipient
        Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add("email@email.com");
        oRecip.Resolve();
        //Set the basic properties. 
        oMsg.Subject = "Job # " + textBox9.Text + " Release (" + textBox1.Text + ")";
        oMsg.HTMLBody = "<html><body>";
        oMsg.HTMLBody += "Job # " + textBox9.Text + " is ready for release attached is the Print and Routing (" + textBox1.Text + ")";
        oMsg.HTMLBody += "<p><a href='C:\\Users\\RussellS\\Desktop\\Russell Eng Reference\\" + textBox1.Text + ".PDF'>" + textBox1.Text + " Drawing";
        oMsg.HTMLBody += "<p><a href='C:\\Users\\RussellS\\Desktop\\" + textBox1.Text + ".PDF'>" + textBox1.Text + " Routing" + "</a></p></body></html>";
        //Send the message
        oMsg.Send();
        //Explicitly release objects. 
        oRecip = null;
        oMsg = null;
        oApp = null;
        MessageBox.Show(textBox1.Text + " Print and Routing Sent");
    }

Solution

  • According to MSDN there's a CC property on the MailItem class.

    string CC { get; set; }
    

    Which can be used to set the names of the CC recipients.

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._mailitem.cc.aspx

    To modify the recipients you can add them to the Recipients collection:

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.recipients.aspx

    Which you would use like:

    oMsg.Recipients.Add("foo@bar.com");