title: Send S/MIME encrypted html email with bash
body: <p>How do you send an <strong>encrypted</strong> and <strong>html-formatted</strong> email through the command line? <br/> Here is the code I have so far:</p>
  
  <pre><code># Encrypt email with a certificate
  openssl cms -encrypt -in "/tmp/email_to_be_sent.html" -out "/tmp/encrypted.txt" -from $SENDER -to $RECEIVER -subject "Test: Encrypted message" -des3 "/tmp/$CERT.pem" 
  # Send the encrypted email
  cat "/tmp/encrypted.txt" | sendmail -f $SENDER $RECEIVER
  </code></pre>
  
  <p>The generated encrypted email <code>/tmp/encrypted.txt</code> is as follow</p>
  
  <pre><code>To: recipient@mail.com
  From: sender@mail.com
  Subject: Test: Encrypted message
  MIME-Version: 1.0
  Content-Disposition: attachment; filename="smime.p7m"
  Content-Type: application/pkcs7-mime; smime-type=enveloped-data;name="smime.p7m"
  Content-Transfer-Encoding: base64
  
  MIIDjAYJKoZIhvcNAQcDoIIDfTCCA3kCAQAxggFZMIIBVQIBADA9MDcxHDAaBgNVBAoME0V1cm9wZWFu
  AxAlApQsmjzCwQoonT57JetCp7DHJdHWU1bkLIZWPPBRwa2EB0ZdxOXIvtg7rJavnnbxeTghblM45Pur
  A+6BDKJbWvXFyxb...
  </code></pre>
  
  <p>The problem is, once in the recipient inbox and decrypted, the message is not html formatted and html code like <code>&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;</code> is still readable inside the message.</p>