C#+LDAP: Email an Lotus Notes Gruppen per SMTP schicken

Problem

In einem Unternehmen sollen Lotus Notes Gruppen aufgelöst werden um den Mitgliedern der LN Gruppe Mails über einen normalen SMTP Server zu schicken

Ansatz

Lotus Notes besitzt i.d.R. einen LDAP Server, der die Notes Gruppen aufschlüsselt. Auf LDAP kann über C# zugegriffen werden.

Lösung

public ArrayList resolvingNotesGroups(String mailGroup)
{
 ArrayList alMailAddys = new ArrayList();

 DirectoryEntry DirEntry = new DirectoryEntry();
 {
  DirEntry.Path = "LDAP://notesldap.it.company.com";
  DirEntry.AuthenticationType = AuthenticationTypes.ServerBind;
 }
   
 DirectorySearcher search = new DirectorySearcher(DirEntry);
 DirectoryEntry de = new DirectoryEntry();

 Dictionary<String, String> dict = new Dictionary<string, string>();

 // Tweak this to refine your search
 search.Filter = "(cn=" + mailGroup + ")";// BBME_AC_Rubi
 // I limit my results while I tweak          
 search.SearchScope = SearchScope.Subtree;          

 try
 {
  SearchResultCollection src = search.FindAll();
        
  if (src.Count != 0)
  {
   foreach (SearchResult result in search.FindAll())
   {
    // Display each of the values for the property 
    // identified by the property name.
    foreach (object property in result.Properties["member"])
    {
     // CN Name ermitteln
     dict.Add(property.ToString(), "");
    }
   }
    
  }
  else
  {
   throw new Exception("GroupResolving - No Entry found for: " + search.Filter);
  }

  int indexStart;
  int indexEnd;


  foreach (KeyValuePair<string, string> entry in dict)
  {
   search.Dispose();
   search = new DirectorySearcher(DirEntry);

   indexStart = entry.Key.IndexOf("=");
   indexEnd = entry.Key.IndexOf(",");

   // Entry key only CN 
   search.Filter = "(cn=" + entry.Key.Substring(indexStart + 1, indexEnd - indexStart - 1) + ")";
   search.SearchScope = SearchScope.Subtree;

   foreach (SearchResult result in search.FindAll())
   {
    if (result != null)
    {

     de = result.GetDirectoryEntry();
     alMailAddys.Add(de.Properties["mail"].Value.ToString());
    }
    else
    {
     throw new Exception("Peolple Resolving - No Entry found for: " + search.Filter);
    }
   }
  }

 }
 catch (Exception ex)
 {
  throw new Exception("Following error occured: " + ex.Message.ToString());
 }
 finally
 {
  search.Dispose();
  DirEntry.Close();
 }

 return alMailAddys;
}}

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.