title: Adding one recipient to MailMessage but add header to email clients see all recipients
body: <p>I am currently working on a C# project where I am making my own SMTP Server. It is more a less working but I am trying to make it work where I can send an email to multiple recipients that are on different domains. </p>
  
  <p>I did initially do it so I would create a <code>MailMesssage</code> object and run the following to add each recipient</p>
  
  <pre><code>MailMessage message = new MailMessage();
  message.To.add("someone@domain1.com");
  message.To.add("someone@domain2.com");
  </code></pre>
  
  <p>If the different domains but going through the google app servers, I would get the MX record which was <code>ALT2.ASPMX.L.GOOGLE.COM</code>. When sending the mail though with the recipients add above google would send an error back as they do not allow cross domain sending via one SMTP session. </p>
  
  <p>Therefore I have reworked it so a separate email is sent for each recipient, I get the MX record for each domain so I end up as well with a different SMTP session. So there would only be one <code>message.To.add</code> for each recipient I received. What I am trying to do is add a header so it still shows that the email recipients are still going to <code>someone@domain1.com</code> and <code>someone@domain2.com</code>. </p>
  
  <p>Therefore as far as the MailMessage component is concerned there is one recipient but the headers show multiple recipients so when the received of the mail views the email in their client it shows all the recipients that the email went to. </p>
  
  <p>Below is the code I have to send the email.</p>
  
  <pre><code>MXLookup mxLookup = new MXLookup();
                      List&lt;string&gt; recipients = addRecipientsToEmail(message.emailRecipients);
                      foreach (string recipient in recipients)
                      {
                          string domain = Classes.CommonTasks.getDomainFromEmail(recipient);
                          string[] mxRecords = mxLookup.getMXRecords(Classes.CommonTasks.getDomainFromEmail(domain));
                          if (mxRecords != null)
                          {
                              MailMessage composedMail = new MailMessage();
                              composedMail.From = new MailAddress(message.EmailFromAddress);
                              composedMail.To.Add(recipient);
                              composedMail.Subject = message.subject;
                              composedMail.Body = message.EmailBody;
                              composedMail.Headers.Add(getHeaders(recipients));
  
                              if (message.contentType.ToString().Contains("text/html"))
                              {
                                  composedMail.IsBodyHtml = true;
                              }
  
                              SmtpClient smtp = new SmtpClient(mxRecords[0]);
                              smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                              smtp.Port = 25;
                              if (Configuration.emailConfig.useSmtpMaxIdleTime)
                              {
                                  smtp.ServicePoint.MaxIdleTime = 1;
                              }
                              library.logging(methodInfo, string.Format("Sending email via MX Record: {0}", mxRecords[0]));
                              smtp.Send(composedMail);
                              updateEmailStatus(message.emailID, EmailStatus.Sent);
                              library.logging(methodInfo, string.Format("Successfully sent email ID: {0}", message.emailID));
  
                          }
  
                          else
                          {
                              string error = string.Format("No MX Record found for domain: {0}", domain);
                              library.logging(methodInfo, error);
                              library.setAlarm(error, CommonTasks.AlarmStatus.Warning, methodInfo);
                          }
  </code></pre>
  
  <p>Below is my getHeaders function. </p>
  
  <pre><code>private NameValueCollection getHeaders(List&lt;string&gt; emailRecipients)
  {
      string headers = "";
      NameValueCollection headersArray = new NameValueCollection();
      foreach (string recipient in emailRecipients)
      {
          headers += string.Format("{0}, ", recipient);
      }
      headersArray.Add("To", headers);
      return headersArray;
  }
  </code></pre>
  
  <p>Thanks for any help you can provide. </p>