title: Exchange server blocks emails with embedded images
body: <p>Unfortunately due to an update made by our exchange server provider, we cannot send emails with embedded images anymore.</p>
  
  <p>As soon as we send the email, we receive this error: "The remote server returned an error: (401) Unauthorized."
  If we remove the image from the email, everything works just fine.
  Is there any work around to this problem?</p>
  
  <p>Our c# code:</p>
  
  <pre><code>AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
  LinkedResource imagelink;
  MatchCollection matches = Regex.Matches(Body, "&lt;img.*?src=\"cid:(.*?)\"");
  foreach (Match match in matches)
  {
      myHttpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri(match.Groups[1].Value));
  
      myHttpWebRequest.UseDefaultCredentials = true;
      myHttpWebRequest.PreAuthenticate = true;
      myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials;
  
      using (myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse())
      {
          receivedStream = myHttpWebResponse.GetResponseStream();
  
          MemoryStream streamReceivedCopy = new MemoryStream();                       
          ImageUtils.CopyStream(receivedStream,streamReceivedCopy);
          var imageType = ImageUtils.GetImageMIMEType(streamReceivedCopy);
          streamReceivedCopy.Position = 0;
          imagelink = new LinkedResource(streamReceivedCopy, imageType);
          imagelink.ContentId = match.Groups[1].Value;
          imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
          htmlView.LinkedResources.Add(imagelink);
      }
  }
  mail.AlternateViews.Add(htmlView);
  </code></pre>
  
  <p>We use then the .net SmtpClient to send the email</p>