title: .NET Application Configuration to store email contact information
body: <p>I have a simple application that sends out status emails to some of our internal users.</p>
  <p>I use a simple application configuration file (App.config) to store email address and name information, about the intended users. Since the appSettings section only seem to support simple key/value pairs, it currently looks like this:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
  &lt;configuration&gt;
    &lt;appSettings&gt;
      &lt;add key=&quot;toName&quot; value=&quot;Recipient Name&quot; /&gt;
      &lt;add key=&quot;toAddr&quot; value=&quot;some@email.com&quot; /&gt;
      &lt;add key=&quot;toName2&quot; value=&quot;Another Recipient Name&quot; /&gt;
      &lt;add key=&quot;toAddr2&quot; value=&quot;another@email.com&quot; /&gt;
      &lt;add key=&quot;ccName&quot; value=&quot;An Archive&quot;/&gt;
      &lt;add key=&quot;ccAddr&quot; value=&quot;copies@email.com&quot;/&gt;
      &lt;add key=&quot;ccName2&quot; value=&quot;Another Archive&quot;/&gt;
      &lt;add key=&quot;ccAddr2&quot; value=&quot;morecopies@email.com&quot;/&gt;
    &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  <p>And then I add each recipient individually in the code.</p>
  <p>Currently, this means that every time I add or remove recipients, I also need to rewrite the code to handle the new recipients and rebuild and re-deploy the application</p>
  <p>I would like to be able to store custom configuration entries, like this maybe:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
  &lt;configuration&gt;
    &lt;recipients&gt;
      &lt;recipient recType=&quot;to&quot; recAddr=&quot;some@email.com&quot; recName=&quot;Recipient Name&quot; /&gt;
      &lt;recipient recType=&quot;to&quot; recAddr=&quot;another@email.com&quot; recName=&quot;Another Recipient Name&quot; /&gt;
      &lt;recipient recType=&quot;cc&quot; recAddr=&quot;copies@email.com&quot; recName=&quot;An Archive&quot;/&gt;
      &lt;recipient recType=&quot;cc&quot; recAddr=&quot;morecopies@email.com&quot; recName=&quot;Another Archive&quot;/&gt;
    &lt;/recipients&gt;
  &lt;/configuration&gt;
  </code></pre>
  <p>So I can loop through them:</p>
  <pre><code>MailMessage message = new MailMessage();
  foreach(recipient rec in recipients)
  {
    MailAddress mailAddress = new MailAddress(recipient[&quot;recAddr&quot;],recipient[&quot;recName&quot;]);
    if(recipient[&quot;recType&quot;] == &quot;cc&quot;)
      message.CC.Add(mailAddress);
    else
      message.To.Add(mailAddress);
  }
  </code></pre>
  <p>How to accomplish this?</p>