添加新的记录,以私人的Outlook通讯组列表
-
22-08-2019 - |
题
我需要阅读包含姓名和电子邮件从一个文件或数据库中的记录,并将其添加到现有的Oulook分发列表(从私下接触,而不是从GAL)。
我刚才看到的,从使用LINQ to我已经工作了邮件和约会DASL OL读书的例子,但我无法弄清楚如何列出一个清单DIST的内容:
private static void GetContacts()
{
Outlook.Application app = new Outlook.Application();
Outlook.Folder folder = (Outlook.Folder)app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
var distLists = from item in folder.Items.AsQueryable<MyDistList>()
where item.DLName == "My Dist List"
select item.Item;
var builder = new StringBuilder();
foreach (var list in distLists)
{
builder.AppendLine(list.DLName);
foreach (var item in list.Members)
{
// can't figure out how to iterate through the members here
// compiler says Object doesn't have GeNumerator...
}
}
Console.WriteLine(builder.ToString());
Console.ReadLine();
}
有一次,我可以读我需要能够添加新的这更加招成员。任何帮助,将不胜感激。
解决方案
原来这是很容易做到。我只是错过了呼叫解决,因为我认为这是唯一的,如果你对GAL解析:
Outlook.Recipient rcp = app.Session.CreateRecipient("Smith, John<j.smith@test.com>");
rcp.Resolve();
list.AddMember(rcp);
list.Save();
和我可以创建使用distList.GetMember方法的迭代器:
//裹DistListItem.GetMembers()作为一个迭代
public static class DistListItemExtensions
{
public static IEnumerable<Outlook.Recipient> Recipients(this Outlook.DistListItem distributionList)
{
for (int i = 1; i <= distributionList.MemberCount; i++)
{
yield return distributionList.GetMember(i);
}
}
}
不隶属于 StackOverflow