Skip to content

Encrypt mail with multiple certificate #297

Closed

Description

@nathinthesky

hello,

more a question for a new feature than an issue. Is it planned to implement encrypted mail for multiple recipients ?

Thanks !

Activity

  1. bbottema commented on Dec 15, 2020

    @bbottema
    Owner

    My knowledge on this is limited, but I think it should already work with multiple recipients, if their keys were signed with a shared CA certificate. Or something like that.

  2. nathinthesky commented on Apr 2, 2021

    @nathinthesky
    Author

    Sorry for delay to answer.
    To encrypt mail for multiple recipients, you have to encrypt it with each recipient certificate (public key), then, they will be able to decrypt the mail on their side with their private key.
    I'll will try to work with you on this !

  3. bbottema commented on Apr 10, 2021

    @bbottema
    Owner

    At one of the companies I worked, they configured a single (CA?) cert, which was used to sign (encrypt?) all emails without needing recipients individual public keys. Is your use case actually really a common one? Seems like a hassle!

  4. nathinthesky commented on Apr 19, 2021

    @nathinthesky
    Author

    I think my case is a common one.

    Usually, a company has its own CA, they use it to sign internal certificates. Each employee then has a key pair (private and public key).

    Let's say I want to send an encrypted mail to Alice and I want her to be the only one to be able to decrypt it. I encrypt it with her public key. The only person able to decrypt the sent mail is the one with the corresponding private key (=Alice).

    Now, I want to send an encrypted mail to Alice and Bob (at the same time, = multiple recipients). If I encrypt it only with Alice public key, only Alice will be able to read it. Bob can't. That's why I need to encrypt it twice : one time with Alice's public key, one time with Bob's one.

    Right now, if I want to do that with simple-java-mail, I have to send 2 distincts emails instead of one.

    I don't know the company you're talking about but if you use only one certificate (you usually don't use a CA for that) to encrypt each email, that means, everybody share the private key and everybody can decrypt them.

    The same if everybody use the same key to sign each email, you can't be sure of who really send it. Usually, you sign it with your private key.

    But maybe that's what they intended to do...

    By the way, in the lib, sign case is ok because you always sign a mail once (= with one private key).

  5. bbottema commented on Apr 24, 2021

    @bbottema
    Owner

    By the way, in the lib, sign case is ok because you always sign a mail once (= with one private key).

    Ahh then that might have been the case at the company I worked for at the time.

    You made a convincing case, one question: this change would mean being able to sign on a per-email basis (so using EmailBuilder). Would it ever make sense to be able to do it on Mailer level as well, affecting all emails that don't have their own key added for signing/encrypting?

  6. nathinthesky commented on Apr 27, 2021

    @nathinthesky
    Author

    you mean to encrypt on a per-email basis ?

    Not sure to understand your question: "do it on Mailer level... emails that don't have their own key added for signing/encrypting"

    As encryption is for a specific recipient, I think certificates has to be done explicitely set in emailBuilder (no default value). For signing, it can be configured as default (as you can choose to sign all your email).

  7. bbottema commented on Apr 29, 2021

    @bbottema
    Owner

    I think certificates has to be done explicitely set in emailBuilder (no default value)

    So no use case whatsoever to allow a default. Ever. (just double checking)

  8. 8 remaining items

  9. jgprospect commented on Dec 26, 2024

    @jgprospect

    bbottema, the documentation you reference to RecipientBuilder looks great. I have version 8.12.4 but I don't see RecipientBuilder in the jar. I also have the SMIME module and the core module and I don't see it listed anywhere. Am I looking in the wrong place? How should I get this functionality? Thanks!

  10. jgprospect commented on Apr 11, 2025

    @jgprospect

    bbottema, I've got the 8.12.5 version of simplejavamail and I don't see the RecipientBuilder changes in it. Do you plan to create a release with RecipientBuilder, etc? Thanks.

  11. bbottema commented on Apr 12, 2025

    @bbottema
    Owner

    I think I've made a mistake with the documentation, it should have been in a separate (unreleased) branch. Sorry for the confusion.

    I intend to pick this up again, but I'm currently on a break from the library. I've been developing it for almost 19 years now, and every now and then I take a long break (6-12 months) before diving back in. Unfortunately, I can't tell when I'm going to pick it up again, sorry. I have a lot going on right now.

    I do still pick up security patches.

  12. jgprospect commented on Apr 12, 2025

    @jgprospect

    Understand.

    I'll look forward to when you make those changes. Until then, I'm very happy using what you've done.

    Thanks.

  13. added a commit that references this issue on Jun 5, 2026
  14. added 4 commits that reference this issue on Jul 3, 2026
  15. added this to the 8.13.0 milestone on Jul 3, 2026
  16. bbottema commented on Jul 3, 2026

    @bbottema
    Owner

    Fixed by making S/MIME encryption certificate selection recipient-aware.

    A Recipient can now carry its own X509Certificate via RecipientBuilder.withSmimeCertificate(...). When any TO/CC/BCC recipient has a certificate, Simple Java Mail uses the per-recipient encryption path; recipient-level certificates override the email-level default, while the email-level SmimeEncryptionConfig can still provide fallback certificates and algorithms.

    Example:

    Recipient alice = new RecipientBuilder()
        .withAddress("alice@example.com")
        .withType(Message.RecipientType.TO)
        .withSmimeCertificate(aliceCertificate)
        .build();
    
    Email email = EmailBuilder.startingBlank()
        .from("me@example.com")
        .to(alice)
        .withPlainText("Encrypted for Alice")
        .buildEmail();

    For multiple recipients, build each Recipient with its own certificate and pass them through .to(...), .cc(...), or .bcc(...).

  17. bbottema commented on Jul 8, 2026

    @bbottema
    Owner

    Released in Simple Java Mail v9.0.0, which is now available from Maven Central:

    https://repo1.maven.org/maven2/org/simplejavamail/simple-java-mail/9.0.0/

    Release notes:
    https://github.com/bbottema/simple-java-mail/releases/tag/9.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions