read email from active directory

 private static string GetEmailAddressLDAP(string strEnv, string empno)

    {

      string strLDAPConnection;

      string strLDAPId;

      string strLDAPPwd;


      if (strEnv.IndexOf("P") == 0)

      {

        //'PROD

        strLDAPConnection = "LDAP://xxxx/ou=xxxx,dc=xx,dc=xxx";

        strLDAPId = @"xxxxxxxxxx";

        strLDAPPwd = "xxxxxxx";

      }

      DirectoryEntry entry = new DirectoryEntry(strLDAPConnection, strLDAPId, strLDAPPwd);

      DirectorySearcher search = new DirectorySearcher(entry);

      char pad = '0';

      search.Filter = String.Format("(sAMAccountName=*{0})", empno.PadLeft(6, pad).Substring(empno.PadLeft(6, pad).Length - 6));

      SearchResult result = search.FindOne();

      if (result != null)

      {

        DirectoryEntry currentUser = result.GetDirectoryEntry();

        if (currentUser.Properties["mail"].Value != null)

        {

          string sEmail = currentUser.Properties["mail"].Value.ToString();

          return sEmail;

        }

        else

        {

          return "email not found";

        }

      }

      else

      {

        return "employee NOT FOUND";

      }

    }

要查看或添加评论,请登录

Daniel Liu的更多文章

  • database table partition

    database table partition

    Some database tables grow and become a super large tables. Usually we either archive or partition the large tables.

  • unable to access to SQL server database diagram

    unable to access to SQL server database diagram

    I login as sa to a SQL server, trying to create a new database diagram, but unable to access it. Got following error…

  • SQL group by sample query

    SQL group by sample query

    query 1: --use group by rollup() select isNull(CONVERT(VARCHAR(4), FILED_RECEIVED_DATE, 126), case when…

  • Validate XML against a schema

    Validate XML against a schema

    private static string ValidateXML(string xsd, string strXml,string emailfrom,string emailto) { string ret = ""; string…

  • C# get first friday in any month, any year

    C# get first friday in any month, any year

    public string GetFirstFriday(int year,int month) { string friday=null; for (int i = 1; i 8; i++) { var dtmDate = new…

  • Blob data and PDF conversion in C#

    Blob data and PDF conversion in C#

    save Blob data from oracle to PDF file: private static void SaveBlobToPDF(string constr, string filing_id) { using…

  • Replace Apostrophe in SQL linked server query

    Replace Apostrophe in SQL linked server query

    I need to search employee's last name from SQL server to DB2 database, one lastname like O'NEIL cause the error, here…

  • send email from c#

    send email from c#

    using System.Net.

  • Multi-tenant Database design

    Multi-tenant Database design

    There are 4 options to design Multi-tenant database: 1. One big database, one schema(dbo): In this approach, database…

  • Create Excel from List<T>

    Create Excel from List<T>

    I need to generate the excel file by querying database everyday. All the data returned as List.

社区洞察

其他会员也浏览了