title: Email with digital signature and embedded image
body: <p>I have the below working code for sending digitally signed emails. I have to insert a html based signature with a gif logo which should be pulled from the assembly resources. I have googled around and found <code>Convert.ToBase64String()</code> as possible solution but Outlook does not display the image.
  The 2nd approach would be <code>LinkedResource</code> with <code>AlternateView</code> to embed my image, but I actually failed to get it work with the below code. I already have an <code>AlternateView</code> to send the email with the digital signature. Is it possible to somehow add the image as well?</p>
  
  <p>So <code>mailer(to, from, from_name, relay, subject, body, cc1, cc2);</code>.</p>
  
  <pre><code>private void mailer(string toaddress, string fromaddress, string fromaddress_disp, string relays, string mailsubject, string bodytext, string ccman, string cccct)
  {
      string certname = "";
  
      MailAddress from = new MailAddress(fromaddress, fromaddress_disp);
      MailAddress to = new MailAddress(toaddress);
      MailAddress cc_man = new MailAddress(ccman);
      MailAddress cc_cct = new MailAddress(cccct);
      MailMessage message = new MailMessage(from, to);
      message.CC.Add(cc_man);
      message.CC.Add(cc_cct);
      message.Subject = mailsubject;
      message.IsBodyHtml = true;
      string body = "Content-Type: text/html; charset=iso-8859-1 \r\nContent-Transfer-Encoding: 8bit\r\n\r\n" + bodytext;
      byte[] messageData = Encoding.ASCII.GetBytes(body);
      ContentInfo content = new ContentInfo(messageData);
  
      SignedCms Cms = new SignedCms(new ContentInfo(messageData));
      X509Store store = new X509Store(StoreLocation.CurrentUser);
      store.Open(OpenFlags.ReadOnly);
  
      RSACryptoServiceProvider csp = null;
      X509Certificate2Collection certCollection = store.Certificates;
      X509Certificate2 cert = null;
      foreach (X509Certificate2 c in certCollection)
      {
          if ((c.Subject.Contains("myEmailAddress")) &amp;&amp; (c.FriendlyName.Contains("CompanyEmailDigSig")))
          {
              cert = c;
              break;
          }
      }
  
      if (cert != null)
      {
              csp = (RSACryptoServiceProvider)cert.PrivateKey;
      }
      else
      {
          throw new Exception("Valid certificate was not found");
      }
  
      CmsSigner Signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, cert);
      Cms.ComputeSignature(Signer);
      byte[] SignedBytes = Cms.Encode();
      MemoryStream signedStream = new MemoryStream(SignedBytes);
      AlternateView signedView = new AlternateView(signedStream, "application/pkcs7-mime; smime-type=signed-data; name=sig.p7m");
      message.AlternateViews.Add(signedView);
      SmtpClient client = new SmtpClient(relays);
      store.Close();
  
      try
      {
          client.Send(message);
      }
      catch (Exception ex)
      {
      //exception
      }
  }
  </code></pre>
  
  <p>EDIT: I had to re-open this thread as the previously accepted answer is not good enough.</p>