title: Embed image to email message in System.Web.Mail.MailMessage
body: <p>I want to send email using System.Web.Mail.MailMessage along with System.Web.Mail.SmtpMail class.
  I know that this is a deprecated class but using System.Net.Mail is not an option for me.</p>
  
  <p>So far I am able to send html formatted mail but I am not able to <strong>embed image to my email</strong> while sending.</p>
  
  <p>This is what I've tried so far;</p>
  
  <pre><code>private static void SendMailMethod(string mailServer, int mailServerPort, string userName, string password)
      {
          const string SMTP_SERVER = "http://schemas.microsoft.com/cdo/configuration/smtpserver";
          const string SMTP_SERVER_PORT =
              "http://schemas.microsoft.com/cdo/configuration/smtpserverport";
  
          const string SEND_USING = "http://schemas.microsoft.com/cdo/configuration/sendusing";
  
          const string SMTP_USE_SSL = "http://schemas.microsoft.com/cdo/configuration/smtpusessl";
  
  
          const string SMTP_AUTHENTICATE =
             "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate";
  
  
          const string SEND_USERNAME =
              "http://schemas.microsoft.com/cdo/configuration/sendusername";
          const string SEND_PASSWORD =
              "http://schemas.microsoft.com/cdo/configuration/sendpassword";
  
  
          var mailMessage = new System.Web.Mail.MailMessage();
  
          mailMessage.Fields[SMTP_SERVER] = mailServer;
          mailMessage.Fields[SMTP_SERVER_PORT] = mailServerPort;
          mailMessage.Fields[SEND_USING] = 2;
          mailMessage.Fields[SMTP_USE_SSL] = false;
          mailMessage.Fields[SMTP_AUTHENTICATE] = 0;
          mailMessage.Fields[SEND_USERNAME] = userName;
          mailMessage.Fields[SEND_PASSWORD] = password;
  
          mailMessage.From = "abc@xyz.com";
          mailMessage.To = "abc@xyz.com";
          mailMessage.Subject = "Test mail:";
          mailMessage.BodyFormat = MailFormat.Html;
  
          var mailAttachment = new MailAttachment("E:\\imageToEmbed.jpg");
          mailMessage.Attachments.Add(mailAttachment);
          mailMessage.Attachments.Add(new MailAttachment("E:\\TestAttachmentFile.txt"));
  
          var htmlBody =
              "&lt;!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"&gt;" +
              "&lt;html xmlns = \"http://www.w3.org/1999/xhtml\" &gt;" +
              " &lt;head &gt;" +
              "&lt;meta http - equiv = \"content-type\" content = \"text/html; charset=UTF-8\" /&gt;" +
              "&lt;/head &gt;" +
              "&lt;body style = \"font-family: Segoe UI; text-align:left;\" &gt;" +
              "Following is an embedded image:" +
              "&lt;br /&gt;" +
              "&lt;img alt = \"\" src = \"imageToEmbed.jpg\" /&gt;" +
              "&lt;/body &gt;" +
              "&lt;/html &gt;";
  
          mailMessage.Body = htmlBody;
  
          try
          {
              SmtpMail.Send(mailMessage);
  
              Console.WriteLine("Mail sent");
          }
          catch (Exception ex)
          {
              Console.WriteLine("Error:" + ex.ToString());
              throw ex;
          }
      }
  </code></pre>
  
  <p>This code sends email but instead of showing image, the mail shows small square with a cross in it.
  How can I embed this "imageToEmbed.jpg" to my email. </p>