Setup: Encryption at rest enabled (OpenPGP, AES-256) both globally and on the account, with “Encrypt on append” enabled.
Problem: When a JMAP client sends a message (Email/set followed by EmailSubmission/set), the message is encrypted with the account owner’s public key when it is created, and the encrypted version is what gets delivered. Recipients receive a PGP/MIME message encrypted to the sender’s key, which they cannot read. In my case, the outbound relay also rejected it with 500 5.2.3 line too long.
Comparison: Clients that send over SMTP and store the copy in Sent over IMAP APPEND (e.g. Thunderbird) are not affected, because the delivered message and the stored copy follow separate paths.
Workaround: Disabling “Encrypt on append” (globally or on the account, followed by a restart for the global setting) fixes sending, but sent messages and drafts are then stored unencrypted.
Expected Behavior
The message should be delivered as the client created it, and only the stored copy (e.g. in Sent) should be encrypted.
Reproduction Steps
Enable encryption at rest (OpenPGP) on a Stalwart account and import the matching private key into OpenKeychain.
Add the account to Sterna (JMAP) and set up OpenPGP with OpenKeychain.
Send a plain-text message to the account from an address without a public key (e.g. Gmail).
Open the message in Sterna and tap Reply.
Sterna does not allow sending the reply unencrypted.
Stalwart Version
v0.16.x
Installation Method
Docker
Database Backend
RocksDB
Blob Storage
RocksDB
Search Engine
Internal
Directory Backend
Internal
I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.
on
I have searched this support forum (open and closed topics) and confirm this is not a duplicate.
on
I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.
Your reading of the behaviour matches the source. The docs don’t say how to avoid it.
On a JMAP create, Email/set ingests the message with IngestSource::Jmap. In crates/email/src/message/ingest.rs, that source is encrypted whenever all three of these are true:
the server-wide encryptAtRest is on,
the server-wide encryptOnAppend is on, and
the account has encryptOnAppend enabled.
The encryption is applied to the stored blob at creation time. EmailSubmission/set then submits that stored message, so it is the already-encrypted blob. That explains the PGP/MIME message sent to the sender’s own key. Nothing in the code or docs separates the “stored copy” from the “message to deliver” for JMAP drafts. IMAP clients like Thunderbird don’t hit this because SMTP submission and the IMAP APPEND of the Sent copy are separate paths.
The docs describe encryptOnAppend as encrypting “messages that the user’s clients store over JMAP or IMAP”, with no exception for messages that are about to be submitted. See Overview | Stalwart and Managing encryption | Stalwart.
You are on v0.16.x, and these docs describe v1.0. I recommend upgrading (Overview | Stalwart) and retesting. I found nothing saying v1.0 changes this behaviour.
For now, the only workaround is the one you found. You can also leave encryptOnAppend off and keep plain encryption at rest. Incoming SMTP mail is still encrypted, but JMAP-created messages such as drafts and sent items are stored unencrypted.
A staff member will follow up on whether this is intended.
This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.
This was a bug. With “Encrypt on append” on, the server encrypted every message a client stored over JMAP, including the one Sterna creates with Email/set just before sending it. EmailSubmission then sends the stored message as is, and since the server never holds your private key it had no way of getting the plaintext back. That’s why your recipients got a PGP/MIME blob addressed to your own key.
Messages created over JMAP with the $draft keyword are now stored unencrypted, so they go out exactly as the client wrote them. That keyword is how JMAP clients normally compose and send. The trade-off is that a message sent over JMAP keeps an unencrypted copy in Sent, because the server can’t swap the stored copy for an encrypted one after it goes out. IMAP appends and everything you receive are still encrypted as before. I’ve added a note about this to the encryption docs.
The fix ships in the next weekly Stalwart release, and you can turn “Encrypt on append” back on once you’ve upgraded.
One suggestion: after a successful EmailSubmission, clients usually ask the server (via onSuccessUpdateEmail) to remove $draft and move the message to Sent. At that point the server still has the plaintext, since the draft is stored unencrypted, so it could encrypt the stored copy then. That way JMAP users would get the same result as IMAP users: messages go out as written, and the copy in Sent ends up encrypted.
I don’t know if what I’m saying is possible or just nonsense. Nor do I know if it makes any practical sense in the JMAP protocol.
I was just looking for a solution similar to IMAP+SMTP, where the email can be sent unencrypted to the client but stored encrypted on the server.
Not nonsense at all, that was one of the options I looked at. It runs into how JMAP treats messages: once an Email exists, its content is fixed. The blobId, size, headers and body can never change for that id (RFC 8621, section 4.1); only keywords and mailboxes can. Encrypting the copy in Sent changes all of those, so the server would have to delete the message and create a new one with a different id, right in the middle of the update the client asked for. Sterna would be left holding a Sent message that no longer exists, and other clients would see it vanish and reappear.
So for now a message sent over JMAP keeps a plain copy in Sent, while everything you receive and anything appended over IMAP stays encrypted.
Hi @stalwart - I’m curious if this is something that would eventually be resolved in a standards update? Or is there anything client or server side that could be done to fix this?
I suppose from my perspective, it feels like a big issue for JMAP to not be able to encrypt sent messages. If we want true encryption at rest, that leaves the potential for a lot of data to be exposed in plain text. Sure messages coming into my account are encrypted by Stalwart before hitting my inbox - but if I reply to any of them, now the full email chain is sitting in plain text in my sent folder.
Right now this is the only thing keeping me from adopting a JMAP email client. So I’m wondering what options we have…