本文介绍了如何将多个收件人添加到mailitem.cc字段C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我正在处理Outlook .msg模板.以编程方式打开它们,并根据数据库中的值插入值.

Oki, so im working on outlook .msg templates.Opening them programmatically, inserting values base on what's in my db.

例如当我想在收件人"字段中添加多个收件人时,而不是按照以下步骤进行操作

ex. when i want to add multiple reciepients at "To" field, instead of doing as following,

   mailitem.To = a + ";" + b + ";" + c;

我在下面做些什么,这比较简单,尤其是当我循环执行时.

i do whats below, which is simpler, especially when i'm doing it in a loop.

   mailitem.Recipients.add("a");
   mailitem.Recipients.add("b");
   mailitem.Recipients.add("c");

我的问题是,我也想在抄送"字段中添加多个收件人,而以上功能仅适用于收件人"字段.如何在不执行字符串操作的情况下将多个收件人添加到抄送"字段.

My problem is, i also want to add multiple recipients at "CC" field and the function above only works for "To" field. How can i add multiple recipients to "CC" field without having to do string manipulation.

通常我会像这样将收件人添加到抄送,

normally i would add recipients to cc like so,

   mailitem.CC = a + ";" + b + ";" + c;

使用interop.outlook并从模板创建邮件项.

im using interop.outlook and creating an mailitem from template.

谢谢.

推荐答案

假设如果您有两个List收件人,那么您可以这样做.

Suppose If you have two List of recipients, then you can do like this.

编辑:包含的完整代码.

var oApp = new Microsoft.Office.Interop.Outlook.Application();
var oMsg = (MailItem) oApp.CreateItem(OlItemType.olMailItem);

Recipients oRecips = oMsg.Recipients;
List<string> sTORecipsList = new List<string>();
List<string> sCCRecipsList = new List<string>();

sTORecipsList.Add("ToRecipient1");

sCCRecipsList.Add("CCRecipient1");
sCCRecipsList.Add("CCRecipient2");
sCCRecipsList.Add("CCRecipient3");

Recipients oRecips = oMsg.Recipients;

foreach (string t in sTORecipsList)
{
    Recipient oTORecip = oRecips.Add(t);
    oTORecip.Type = (int) OlMailRecipientType.olTo;
    oTORecip.Resolve();
}

foreach (string t in sCCRecipsList)
{
    Recipient oCCRecip = oRecips.Add(t);
    oCCRecip.Type = (int) OlMailRecipientType.olCC;
    oCCRecip.Resolve();
}

oMsg.HTMLBody = "Test Body";
oMsg.Subject = "Test Subject";
oMsg.Send();

这篇关于如何将多个收件人添加到mailitem.cc字段C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 12:32