将新记录添加到私人 Outlook 通讯组列表
我需要从文件或数据库中读取包含姓名和电子邮件的记录,并将它们添加到现有的 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();
}
一旦我可以读取成员,我就需要能够添加新的,这更是技巧。 任何帮助,将不胜感激。
I need to read records containing name and email from a file or database and add them to an existing Oulook distribution list (from the private contacts, not from the GAL).
I just saw examples of reading from OL using LINQ to DASL which I have working for mail and appointments, but I can't figure out how to list the contents of a dist list:
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();
}
Once I can read the members I need to be able to add new ones which is even more trick. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明这很容易。 我只是错过了对 Resolve 的调用,因为我认为只有在针对 GAL 进行解析时才会这样:
我可以创建一个使用 distList.GetMember 方法的迭代器:
// Wrap DistListItem.GetMembers() as an iterator
Turns out it is easy enough. I was simply missing the call to Resolve as I thought that was only if you were resolving against the GAL:
And I can create an iterator that uses the distList.GetMember method:
// Wrap DistListItem.GetMembers() as an iterator