EmailMessage.java

  1. package no.nav.data.common.mail;

  2. import java.util.List;

  3. public record EmailMessage(
  4.         Message message
  5. ) {
  6.     public EmailMessage(String subject, String content, List<String> recipientsEmailAddresses) {
  7.         this(new Message(subject, recipientsEmailAddresses, new Message.Body("HTML", content)));
  8.     }

  9.     public record Message(
  10.             String subject,
  11.             Body body,
  12.             List<Recipient> toRecipients
  13.     ) {

  14.         public Message(String subject, List<String> recipientsEmailAddresses, Body body) {
  15.             this(subject, body, recipientsEmailAddresses.stream().map(Recipient::new).toList());
  16.         }

  17.         public record Body(
  18.                 String contentType,
  19.                 String content
  20.         ) {}

  21.         public record Recipient(
  22.                 EmailAddress emailAddress
  23.         ) {
  24.             public Recipient(String address) {
  25.                 this(new EmailAddress(address));
  26.             }

  27.             public record EmailAddress(
  28.                     String address
  29.             ) {}
  30.         }
  31.     }
  32. }