title: VSTO Outlook Add-in: Zip COM Object
body: <p>I am trying to zip an email received before it gets attached to another email. So I am stuck with the zip part. The object that I am trying to zip is a COM Object and doesn't support serialization. Any ideas that can help me progress with this are welcome!</p>
  
  <p>And the code so far (selObject is the COM Object):</p>
  
  <pre><code>private void Report_Malicious_Email_Click(object sender, RibbonControlEventArgs e)
  {
      // selObject este mailul selectat
      Object selObject = this.Application.ActiveExplorer().Selection[1];
      if (selObject is Outlook.MailItem) // de aici incepe logica pentru forward cu atasament! 
      {
          using (MemoryStream msCompressed = new MemoryStream())
          using (GZipStream gZipStream = new GZipStream(msCompressed, CompressionMode.Compress))
          using (MemoryStream msDecompressed = new MemoryStream())
          {
              new BinaryFormatter().Serialize(msDecompressed, selObject);
              byte[] byteArray = msDecompressed.ToArray();
  
              gZipStream.Write(byteArray, 0, byteArray.Length);
              gZipStream.Close();
              msCompressed.ToArray();
          }
  
          Outlook.MailItem eMail = 
              (Outlook.MailItem)this.Application.CreateItem(Outlook.OlItemType.olMailItem);
          eMail.Subject = subjectEmail;
          eMail.To = toEmail;
          eMail.Body = bodyEmail;
          eMail.Attachments.Add(selObject);
          eMail.Send();
      }
  }
  </code></pre>