Question

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");
    }
Was it helpful?

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");

OTHER TIPS

Please follow this code for adding CC and BCC:

private void SetRecipientTypeForMail()
{
    Outlook.MailItem mail = Application.CreateItem(
        Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    mail.Subject = "Sample Message";
    Outlook.Recipient recipTo =
        mail.Recipients.Add("someone@example.com");
    recipTo.Type = (int)Outlook.OlMailRecipientType.olTo;
    Outlook.Recipient recipCc =
        mail.Recipients.Add("someonecc@example.com");
    recipCc.Type = (int)Outlook.OlMailRecipientType.olCC;
    Outlook.Recipient recipBcc =
        mail.Recipients.Add("someonebcc@example.com");
    recipBcc.Type = (int)Outlook.OlMailRecipientType.olBCC;
    mail.Recipients.ResolveAll();
    mail.Display(false);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top