Sending a PGP email with nodemailer-openpgp is encrypting properly but causing an SMTP API Error

744 Views Asked by At

Attempting to send a pgp encrypted email via nodemailer-openpgp

Sending via Postmark triggers this SMTP APi Error

ErrorCode: '300', Message: 'Provide either email TextBody or HtmlBody or both.'.

Here is the function that sends the email

 async function sendPGPEncryptedEmail (pubKey, mailerOpts) {
   try {
     const defaultOpts = {
       from: process.env.POSTMARK_FROM_ADDRESS,
       to: '[email protected]',
       subject: 'Confirm your Email',
       text: 'heyeyey',
       html: 'yoyoyo',
       message: "hey message man!",
     }

     const opts = Object.assign(defaultOpts, mailerOpts)

     const transporter = nodemailer.createTransport({
       service: 'Postmark',
       auth: {
         user: process.env.POSTMARK_API_KEY,
         pass: process.env.POSTMARK_API_KEY
       }
     })

     opts.encryptionKeys = [pubKey]
     transporter.use('stream', openpgpEncrypt()) 
     let response = await transporter.sendMail(opts)
     return response
   } catch (err) {
     console.error(err)
     throw err;
   }
 }

Here is the raw email delivered to Postmark

Content-Description: OpenPGP encrypted message
Received: from MacBook-Pro.local ([insert my ip address here])
    (Authenticated sender: *****valid api key here *****)
    by smtp.postmarkapp.com (Postfix) with ESMTPSA id B9AF02C0ABB
    for <[email protected]>; Wed,  8 Aug 2018 22:49:04 -0400 (EDT)
From: [email protected]
To: [email protected]
Subject: Confirm your Email
Message-ID: <[email protected]>
Date: Thu, 09 Aug 2018 02:48:11 +0000
MIME-Version: 1.0
Content-Type: multipart/mixed;
    boundary="----=_NextPart_000_F685_1CAC7FB5.7E7A4394"


------=_NextPart_000_F685_1CAC7FB5.7E7A4394
Content-Type: multipart/encrypted; protocol="application/pgp-encrypted";
 boundary="nm_2c44dd8ede19acb90c35a95fbecb"
Content-Description: OpenPGP encrypted message
Content-Transfer-Encoding: 7bit


This is an OpenPGP/MIME encrypted message

--nm_2c44dd8ede19acb90c35a95fbecb
Content-Type: application/pgp-encrypted
Content-Transfer-Encoding: 7bit

Version: 1

--nm_2c44dd8ede19acb90c35a95fbecb
Content-Type: application/octet-stream; name=encrypted.asc
Content-Disposition: inline; filename=encrypted.asc
Content-Transfer-Encoding: 7bit

-----BEGIN PGP MESSAGE-----
Version: OpenPGP.js v3.0.11
Comment: https://openpgpjs.org

wcBMA/FPIJCgms04AQf+PxAO/HsmYa46AQDV+3AISLa/No3BhRs7QDiFzjs/
2i04b7CNvMVry3/bP+oklwhf4fpgVV8HstCpaEEMyIlXThblYmba2i78CjIt
r8AnYIh5F3o8bnc/wcqTb5sJD5Y/hVfKxTQCLlrqOqDqmyyNhdxipwiUmqwi
GR8NxGuKrkvWxpBLCKCp5THwn9v9pS95ftjPOnakAUlfqUusB/BjtvtWRImP
QmvKWnCYt2+tUTGqTnB0B12Q1z9mAiAsidj9UActn1ED2WwBt/0/Vke9aUKC
vYjxUYqt+qmJ9hOuPXTn4Yr9BfzL4ksvepAptMR3vn62kbSeiJh2VBITJTg+
QdLBYAECnfa4Cvzb6KtMqvrYju6cNZwTabjdwWyo4n76uZ8EAdKJ3ixAVoby
fNFfthYHb0iUR4SdArp0PfoJtQRqrgry0XDfIZLR6jDTrBlMA407V5dZi1jI
uA1epT0oS7ksDxKngP3zE03zJfvFYkraOAj/PqEhdQL9FHvM767ZgfTBiW2g
qy7vCn4UvhGYi0rg7xXVHTs4FxzumQ4c8uZP0iFW9rS5C0MPai6mZr4r3xZr
HJAmobQcV8RAqMseO+jMqw8SkqFidtKpqYUtQH0ehrmXTq9JkxlAhWV2p5FY
XVNSYB84ytll2oi39uAyiRYZb495VNj5lzZKQi4MVJa90NEZqM6oZvJC+hOi
KwbkPeMhp7NdJ+n4H53oSfrWXB7zGUpKe+73C/8y+xUvSVWeudkJ4t1HrgyA
cWc1Eyw5o/7gTOSIqMRBUm7KzxR7xkFB5DcvXsalQ5g09jqjDpIw6t3J8uIU
EDAtH3k6299SHpY29wxa5JWjK0DsqQkP1Qrml+8wI74rk7xQBiPFTtDn1QP+
3YwL/q/smo9GPcWx2eS2NrM/65y4/f5qaGbb4S7ymo4Jo4MoMzin9ko7GR3S
gxQXDNS9qzo5OMESSBz2Ofr9rRRav7nhXa7hQwagqJsWWKXPNMOZtGgxAf4s
y2vzUmEDWJP1FhMkc5oZJ2h8PaU2ITaAXaElOqU+1U1019ClY2zxtkjofRV+
iV0HQvSq+IQ=
=VY27
-----END PGP MESSAGE-----

--nm_2c44dd8ede19acb90c35a95fbecb--

------=_NextPart_000_F685_1CAC7FB5.7E7A4394
Content-Type: application/pgp-encrypted
Content-Transfer-Encoding: 7bit

Version: 1

------=_NextPart_000_F685_1CAC7FB5.7E7A4394
Content-Type: application/octet-stream; name=encrypted.asc
Content-Disposition: inline; filename=encrypted.asc
Content-Transfer-Encoding: 7bit

-----BEGIN PGP MESSAGE-----
Version: OpenPGP.js v3.0.11
Comment: https://openpgpjs.org

wcBMA/FPIJCgms04AQf+PxAO/HsmYa46AQDV+3AISLa/No3BhRs7QDiFzjs/
2i04b7CNvMVry3/bP+oklwhf4fpgVV8HstCpaEEMyIlXThblYmba2i78CjIt
r8AnYIh5F3o8bnc/wcqTb5sJD5Y/hVfKxTQCLlrqOqDqmyyNhdxipwiUmqwi
GR8NxGuKrkvWxpBLCKCp5THwn9v9pS95ftjPOnakAUlfqUusB/BjtvtWRImP
QmvKWnCYt2+tUTGqTnB0B12Q1z9mAiAsidj9UActn1ED2WwBt/0/Vke9aUKC
vYjxUYqt+qmJ9hOuPXTn4Yr9BfzL4ksvepAptMR3vn62kbSeiJh2VBITJTg+
QdLBYAECnfa4Cvzb6KtMqvrYju6cNZwTabjdwWyo4n76uZ8EAdKJ3ixAVoby
fNFfthYHb0iUR4SdArp0PfoJtQRqrgry0XDfIZLR6jDTrBlMA407V5dZi1jI
uA1epT0oS7ksDxKngP3zE03zJfvFYkraOAj/PqEhdQL9FHvM767ZgfTBiW2g
qy7vCn4UvhGYi0rg7xXVHTs4FxzumQ4c8uZP0iFW9rS5C0MPai6mZr4r3xZr
HJAmobQcV8RAqMseO+jMqw8SkqFidtKpqYUtQH0ehrmXTq9JkxlAhWV2p5FY
XVNSYB84ytll2oi39uAyiRYZb495VNj5lzZKQi4MVJa90NEZqM6oZvJC+hOi
KwbkPeMhp7NdJ+n4H53oSfrWXB7zGUpKe+73C/8y+xUvSVWeudkJ4t1HrgyA
cWc1Eyw5o/7gTOSIqMRBUm7KzxR7xkFB5DcvXsalQ5g09jqjDpIw6t3J8uIU
EDAtH3k6299SHpY29wxa5JWjK0DsqQkP1Qrml+8wI74rk7xQBiPFTtDn1QP+
3YwL/q/smo9GPcWx2eS2NrM/65y4/f5qaGbb4S7ymo4Jo4MoMzin9ko7GR3S
gxQXDNS9qzo5OMESSBz2Ofr9rRRav7nhXa7hQwagqJsWWKXPNMOZtGgxAf4s
y2vzUmEDWJP1FhMkc5oZJ2h8PaU2ITaAXaElOqU+1U1019ClY2zxtkjofRV+
iV0HQvSq+IQ=
=VY27
-----END PGP MESSAGE-----

------=_NextPart_000_F685_1CAC7FB5.7E7A4394--
Does this bounce type look incorrect? Notify us.

removing the openpgp transform results in the email being delived without issue in plaintext

// transporter.use('stream', openpgpEncrypt())  

So it looks to me like Postmark is getting a multipart encrypted email. So why is it throwing an error and refusing to deliver? Your assistance is much appreciated

Here is the nodemailer plugin https://github.com/nodemailer/nodemailer-openpgp It is a plugin that adds a transform to the mail message stream.

0

There are 0 best solutions below