title: How to embed multiple images in email body using .NET
body: <p>I'm writing a program that sends emails to users with multiple images (charts) embedded in the Email message body (HTML).</p>
  
  <p>When I tried the sample located here..which worked well when I have to embed only one image
  <a href="http://www.systemnetmail.com/faq/4.4.aspx" rel="noreferrer">http://www.systemnetmail.com/faq/4.4.aspx</a>.</p>
  
  <p>But, when i tried to embed multiple images using the below code, none of the images are being embedded , instead they are sent as attachments.</p>
  
  <pre><code>public MailMessage MailMessage(Metric metric, DateTime date)
  {
      MailMessage msg = new MailMessage();
      msg.From = new MailAddress("test@gmail.com", "User1");
      msg.To.Add(new MailAddress("test@gmail.com"));
      msg.Subject = "Trend for metric: " + metric.Name;
      msg.IsBodyHtml = true;
  
      // Generate the charts for the given metric
      var charts = this.GenerateCharts(metric, date);
      int i = 0;
      string htmlBody = "&lt;html&gt;&lt;body&gt;";
      List&lt;LinkedResource&gt; resources = new List&lt;LinkedResource&gt;();
      foreach (var chart in charts)
      {
          string imageTag = string.Format("&lt;img src=cid:chart{0} /&gt;&lt;br&gt;", i);
          htmlBody += imageTag;
          LinkedResource graph = new LinkedResource(chart.Value, "image/jpeg");
          graph.ContentId = "chart" + i;
          resources.Add(graph);
          i++;
      }
  
      htmlBody += "&lt;/body&gt;&lt;/html&gt;";
  
      // Alternate view for embedded images
      AlternateView avText = AlternateView.CreateAlternateViewFromString(metric.Name, null, MediaTypeNames.Text.Html);
      AlternateView avImages = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
  
      // Add all the images as linked resources
      resources.ForEach(x =&gt; avImages.LinkedResources.Add(x));
  
      // Add the views for image
      msg.AlternateViews.Add(avText);
      msg.AlternateViews.Add(avImages);
  
  
      return msg;
  }
  </code></pre>
  
  <p>Any clues as what I'm missing?
  I checked the .htm file which is also sent as attachment with the email, and html source looks as follows:</p>
  
  <pre><code>&lt;html&gt;&gt;&lt;body&gt;&lt;img src=cid:chart0 /&gt;&lt;br&gt;&lt;img src=cid:chart1 /&gt;&lt;br&gt;&lt;img src=cid:chart2/&gt;&lt;br&gt;&lt;img src=cid:chart3 /&gt;&lt;br&gt;&lt;img src=cid:chart4 /&gt;&lt;br&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>So the Q is how to send multiple images in the html body , not as attachment.</p>