title: Sending S/MIME encrypted emails through SendGrid SMTP
body: <p>I am setting up a WordPress site that will send S/MIME encrypted emails via SendGrid using a plugin called WP PGP Encrypted Emails (looks like it uses PHP's openssl_pkcs7_encrypt). I have successfully sent, and decrypted S/MIME emails with my hosting provider's postfix SMTP servers. However I have to take into account deliverability, so I would like to use SendGrid (which is not a changeable requirement for me) to improve their deliverability.</p>
  <p>The issue that I am running into is that first SendGrid's API will reject emails that have the content-transfer-encoding set to &quot;base64&quot;. I don't know how significant this header is in the context of S/MIME emails, but whenever I remove it or change it, my emails don't come through as expected. I did some research and found that the API simply doesn't allow changing this header, but that I should be able to modify the content-transfer-encoding header if I send directly to SendGrid's SMTP at smtp.sendgrid.net. If I do that, I can indeed send out an email that arrives with an encrpyted attachment, as expected. The problem is that when I try to decrypt the attachment in Outlook (another requirement), I get a message saying that &quot;the underlying security system cannot verify your Digital ID&quot;.</p>
  <p>My questions are whether or not anyone has encountered this issue before and been able to resolve it, do SendGrid SMTP servers allow content-transfer-encoding to be modified, and what role does this header play in sending and recieving S/MIME encrypted emails?</p>
  <p>Edit: Email Headers</p>
  <pre><code>X-Mailer: PHPMailer 6.5.3 (https://github.com/PHPMailer/PHPMailer)
  Content-Disposition: attachment; filename=&quot;smime.p7m&quot;
  Content-Transfer-Encoding: base64
  MIME-Version: 1.0
  Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name=&quot;smime.p7m&quot;; charset=UTF-8
  </code></pre>