我目前正在尝试从我的全球地址列表中提取分发列表电子邮件。我现在有部分功能,部分意思是我目前能够成功提取分发列表的名称,但不能提取电子邮件。这是我到目前为止所拥有的:
public class DistributionListDetails
{
public string DistributionListId { get; set; }
public string DistributionListEmail { get; set; }
}
public List<DistributionListDetails> DistributionListInformtion { get; set; }
[WebMethod]
public static List<DistributionListDetails> GetDistributionLists()
{
List<DistributionListDetails> distributionLists = new List<DistributionListDetails>();
//create Outlook application.
Outlook.Application oApp = new Outlook.Application();
//get Mapi NameSpace and Logon.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
//get Global Address List.
Outlook.AddressLists oDLs = oNS.AddressLists;
Outlook.AddressList oGal = oDLs["Global Address List"];
//get a specific distribution list.
string sDL = "TestDL";
Outlook.AddressEntries oEntries = oGal.AddressEntries;
Outlook.AddressEntry oDL = oEntries[sDL];
if (oDL.Manager != null)
distributionLists.Add(new DistributionListDetails
{
DistributionListId = oDL.Name,
DistributionListEmail = oDL.Manager.ToString()
});
//get all of the members of the distribution list.
oEntries = oDL.Members;
Outlook.AddressEntry oEntry = default(Outlook.AddressEntry);
//adding distribution lists to list
distributionLists.AddRange(oGal.AddressEntries.Cast<Outlook.AddressEntry>().Select(
x => new DistributionListDetails
{
DistributionListId = x.Name,
DistributionListEmail = x.Name
}).Take(400));
//log off.
oNS.Logoff();
//clean up.
oApp = null;
oNS = null;
oDLs = null;
oGal = null;
oEntries = null;
oEntry = null;
return distributionLists;
}
我基本上是在使用该Interop Outlook
服务(我对此并不感到兴奋)打开 Outlook 并从全球地址列表中检索分发列表的名称。在我的 LINQ 查询中,我认为我能够获取 DL 电子邮件地址是这样的:
DistributionListID = x.Email
或类似性质的东西,但它没有给我任何类似的选择。我的最终产品是我想通过 Web 应用程序通过电子邮件发送分发列表(因此我需要电子邮件地址)。我以为我可以严格使用这个名称,因为我使用的是 Interop,它会很聪明地通过电子邮件发送它,但我错了。
目前我正在扔它:
My Distribution List
但它期待这一点(这确实有效,我已经在调试中对其进行了测试):
My Distribution List <MyDistributionListEmail@mycompany.com>
那么,在所有这些之后,有人对我如何提取 DL 的电子邮件地址有任何建议吗?