我目前正在使用C#中的2013 Outlook API,并在遇到奇怪的问题时正在创建联系人组(datalist)。
我可以使用以下代码创建一个联系人组,但是在创建后,联系人组似乎不包含任何联系人。
但是,在创建组并添加联系人(必须具有电子邮件地址的过滤器)检查时,我可以看到联系人在保存之前存储在联系人组的显示中。
Outlook.DistListItem distList = Application.CreateItem(Outlook.OlItemType.olDistributionListItem) as Outlook.DistListItem;
distList.Subject = "TEST GROUP";
// grab all addresses such that primary email is not an empty string
string filter = "[Email1Address] <> ''";
// grab the table of users
Outlook.Table table = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).GetTable(filter, Outlook.OlTableContents.olUserItems);
// addingin email address so table must have column to represent this
table.Columns.Add("Email1Address");
while (!table.EndOfTable)
{
Outlook.Row nextRow = table.GetNextRow();
if (nextRow["Email1Address"] == null)
{
// no more addresses left to process.
break;
}
else
{
// create a recipient based upon information in our table
Outlook.Recipient recipient = Application.Session.CreateRecipient(nextRow["Email1Address"].ToString());
// ensure recipient is valid by checking our address book for resolution
recipient.Resolve();
MessageBox.Show(recipient.ToString() + "\nEOT: " + table.EndOfTable);
distList.AddMember(recipient);
}
}
// name the list?
distList.DLName = "Testing addin";
// save the list
distList.Save();
尝试向此联系人群组发送电子邮件时,系统会提示我,并显示以下错误消息:
此邮件发送给的联系人组必须至少包含一个收件人。
答案 0 :(得分:0)
我从OutlookSpy运行以下脚本没有问题(单击OutlookSpy功能区上的脚本按钮,粘贴脚本,单击运行):
set DL = Application.Session.GetDefaultFolder(olFolderContacts).Items.Add(olDistributionListItem)
set Recip = Application.Session.CreateRecipient("test@domain.demo")
Recip.Resolve
DL.AddMember(Recip)
DL.DLName = "Testing addin"
DL.Save