我目前正在尝试从我的全局地址列表中提取通讯组列表电子邮件。我现在可以部分运行,部分运行是指我目前能够成功提取通讯组列表的名称,但不能提取电子邮件。这是我到目前为止所拥有的:
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
或者类似的东西,但它没有给我任何类型的选择。我的最终产品是我想从网络应用程序通过电子邮件发送通讯组列表(因此我需要电子邮件地址)。我以为我可以严格使用该名称,因为我使用的是 Interop,并且通过电子邮件发送它会足够聪明,但我错了。
目前我正在抛出它:
My Distribution List
但它期待这个(这确实有效,我已经在调试中测试了它):
My Distribution List <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8dc0f4c9e4fef9ffe4eff8f9e4e2e3c1e4fef9c8e0ece4e1cde0f4eee2e0fdece3f4a3eee2e0" rel="noreferrer noopener nofollow">[email protected]</a>>
那么,在这一切之后,有没有人对我如何提取 DL 的电子邮件地址有任何建议?
最佳答案
使用AddressEntry.Address
。如果您需要 SMTP 添加器,请使用 AddressEntry.GetExchangeUser().PrimarySmtpAddress
。
不要将 LINQ 与 OOM 对象一起使用,应使用古老的“for”循环。
关于c# - 从全局地址列表中提取电子邮件(不是姓名),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34299945/