gpt4 book ai didi

c# - 从全局地址列表中提取电子邮件(不是名称)

转载 作者:行者123 更新时间:2023-11-30 23:32:29 25 4
gpt4 key购买 nike

我目前正在尝试从我的全局地址列表中提取通讯组列表电子邮件。我现在有部分功能,我的部分意思是我目前能够成功提取通讯组列表的名称,但不能提取电子邮件。这是我目前所拥有的:

    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 <MyDistributionListEmail@mycompany.com>

那么在所有这些之后,有没有人对我如何提取 DL 的电子邮件地址有任何建议?

最佳答案

使用 AddressEntry.Address。如果您需要 SMTP 添加器,请使用 AddressEntry.GetExchangeUser().PrimarySmtpAddress

不要将 LINQ 与 OOM 对象一起使用,使用一个很好的旧“for”循环。

关于c# - 从全局地址列表中提取电子邮件(不是名称),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34299945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com