我需要在C#应用程序中从outlook获取电子邮件I才能发送邮件。我有userId或者FirstName和LastName。请给我推荐一个合适的方法。
谢谢
发布于 2010-07-23 19:02:10
public string GetEmaiId(string userId)
{
string email = string.Empty;
DirectorySearcher objsearch = new DirectorySearcher();
string strrootdse = objsearch.SearchRoot.Path;
DirectoryEntry objdirentry = new DirectoryEntry(strrootdse);
objsearch.Filter = "(& (cn=" + userId + ")(objectClass=user))";
objsearch.SearchScope = System.DirectoryServices.SearchScope.Subtree;
objsearch.PropertiesToLoad.Add("cn");
objsearch.PropertyNamesOnly = true;
objsearch.Sort.Direction = System.DirectoryServices.SortDirection.Ascending;
objsearch.Sort.PropertyName = "cn";
SearchResultCollection colresults = objsearch.FindAll();
foreach (SearchResult objresult in colresults)
{
email = objresult.GetDirectoryEntry().Properties["mail"].Value.ToString();
}
objsearch.Dispose();
return email;
}https://stackoverflow.com/questions/3279626
复制相似问题