Microsoft Outlook 添加抄送至电子邮件

发布于 2024-12-04 07:37:26 字数 1675 浏览 2 评论 0原文

我目前拥有自动执行电子邮件和发送文件的现有代码。我现在需要添加一个抄送。我已经全部查看过了,但似乎无法用我现有的代码找出答案。任何帮助将不胜感激。谢谢。

         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 protected]");
        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");
    }

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 protected]");
        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");
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔戏命师 2024-12-11 07:37:26

根据 MSDN,MailItem 类上有一个 CC 属性。

string CC { get; set; }

可用于设置抄送收件人的姓名。

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

要修改收件人,您可以将它们添加到收件人集合中:

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

您将使用如下:

oMsg.Recipients.Add("[email protected]");

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("[email protected]");
一个人练习一个人 2024-12-11 07:37:26

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

private void SetRecipientTypeForMail()
{
    Outlook.MailItem mail = Application.CreateItem(
        Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    mail.Subject = "Sample Message";
    Outlook.Recipient recipTo =
        mail.Recipients.Add("[email protected]");
    recipTo.Type = (int)Outlook.OlMailRecipientType.olTo;
    Outlook.Recipient recipCc =
        mail.Recipients.Add("[email protected]");
    recipCc.Type = (int)Outlook.OlMailRecipientType.olCC;
    Outlook.Recipient recipBcc =
        mail.Recipients.Add("[email protected]");
    recipBcc.Type = (int)Outlook.OlMailRecipientType.olBCC;
    mail.Recipients.ResolveAll();
    mail.Display(false);
}

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("[email protected]");
    recipTo.Type = (int)Outlook.OlMailRecipientType.olTo;
    Outlook.Recipient recipCc =
        mail.Recipients.Add("[email protected]");
    recipCc.Type = (int)Outlook.OlMailRecipientType.olCC;
    Outlook.Recipient recipBcc =
        mail.Recipients.Add("[email protected]");
    recipBcc.Type = (int)Outlook.OlMailRecipientType.olBCC;
    mail.Recipients.ResolveAll();
    mail.Display(false);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文