C# Microsoft Outlook将抄送添加到电子邮件

C# Microsoft Outlook将抄送添加到电子邮件,c#,winforms,outlook,carbon-copy,C#,Winforms,Outlook,Carbon Copy,我目前有自动发送电子邮件和发送文件的现有代码。我现在需要添加一个cc。我已经找遍了,但似乎无法用我现有的代码找到答案。任何帮助都将不胜感激。多谢各位 private void button13_Click(object sender, EventArgs e) { //Send Routing and Drawing to Dan // Create the Outlook application by using inline init

我目前有自动发送电子邮件和发送文件的现有代码。我现在需要添加一个cc。我已经找遍了,但似乎无法用我现有的代码找到答案。任何帮助都将不胜感激。多谢各位

         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");
    }
private void按钮13\u单击(对象发送者,事件参数e)
{
//将工艺路线和图纸发送给Dan
//使用内联初始化创建Outlook应用程序。
Outlook.Application oApp=新建Outlook.Application();
//使用最简单的方法创建新消息。
Outlook.MailItem oMsg=(Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
//添加收件人
Outlook.Recipient oRecip=(Outlook.Recipient)oMsg.Recipients.Add(“email@email.com");
oRecip.Resolve();
//设置基本属性。
oMsg.Subject=“作业”#“+textBox9.Text+”发布(“+textBox1.Text+”);
oMsg.HTMLBody=“”;
oMsg.HTMLBody+=“作业#”+textBox9.Text+”已准备好发布,随附的是打印和布线(“+textBox1.Text+”);
oMsg.HTMLBody+=“

”; //发送消息 oMsg.Send(); //显式释放对象。 oRecip=null; oMsg=null; oApp=null; MessageBox.Show(textBox1.Text+“已发送打印和路由”); }
根据MSDN,MailItem类上有一个CC属性

string CC { get; set; }
可用于设置抄送收件人的名称

要修改收件人,可以将其添加到“收件人”集合:

您将使用以下选项:

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

请按照此代码添加抄送和密件抄送:

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

这实际上是可行的,但它增加了outlook上的to:而不是cc,因此我是否必须在某个位置的行中字符串cc?据我所知,将带有cc收件人名称的cc属性设置为与收件人集合中的收件人匹配的内容就够了。我知道这个答案已被接受,我只是想补充一点,Microsoft建议您通过recipients集合操纵收件人。收件人、抄送和密件抄送属性只能用于读取收件人。要设置抄送收件人,您可以在上面添加新收件人的Jamie代码之后将Type属性设置为olCC(或对于BCC收件人设置为olBCC)。