Class DraftEmail

java.lang.Object
de.gustavblass.commons.email.DraftEmail

public class DraftEmail extends Object
  • Field Details

    • LOG

      private static final org.apache.logging.log4j.Logger LOG
    • subject

      @NonNull private @NonNull String subject
      What the e-mail is about. Will be shown in the subject line of the e-mail client.
    • message

      @NonNull private @NonNull String message
      The actual content of the e-mail.
    • recipients

      @NonNull private @NonNull Set<jakarta.mail.internet.InternetAddress> recipients
      Whom the e-mail shall be sent to.
    • ccRecipients

      @NonNull private @NonNull Set<jakarta.mail.internet.InternetAddress> ccRecipients
      Whom the e-mail shall be carbon-copied to.
    • bccRecipients

      @NonNull private @NonNull Set<jakarta.mail.internet.InternetAddress> bccRecipients
      Whom the e-mail shall be blind-carbon-copied to.
    • attachments

      @NonNull private @NonNull Set<File> attachments
      Any number of files to send along with the message.
    • publicKeys

      @NonNull private @NonNull Set<String> publicKeys
      Any number of PGP public keys to encrypt the message with. It does not matter if the keys are of RSA or ECC type, as long as they support encryption. (Though, RSA is very strongly discouraged!)
    • fallBackToUnencrypted

      private boolean fallBackToUnencrypted
      If the e-mail could not be encrypted, should it be sent unencrypted?
    • saveToSentFolder

      private boolean saveToSentFolder
      Whether the e-mail should be stored in the “sent” folder of the user's inbox.
  • Constructor Details

    • DraftEmail

      public DraftEmail(@NonNull @NonNull String subject, @NonNull @NonNull String message, @NonNull @NonNull Set<jakarta.mail.internet.InternetAddress> recipients) throws de.gustavblass.commons.exceptions.IllegalArgumentException
      Creates a new draft e-mail.
      Parameters:
      subject - The subject of the e-mail.
      message - The actual content of the e-mail.
      recipients - The recipients of the e-mail. At least one e-mail address must be specified.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If no recipient is set.
    • DraftEmail

      public DraftEmail(@NonNull @NonNull String subject, @NonNull @NonNull String message, @NonNull @NonNull Set<jakarta.mail.internet.InternetAddress> recipients, @NonNull @NonNull Set<File> attachments) throws de.gustavblass.commons.exceptions.IllegalArgumentException
      Creates a new draft e-mail.
      Parameters:
      subject - The subject of the e-mail.
      message - The actual content of the e-mail.
      recipients - The recipients of the e-mail. At least one e-mail address must be specified.
      attachments - Any number of files to send along with the message.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If no recipient is set.
  • Method Details

    • setSubject

      public void setSubject(@NonNull @NonNull String subject)
      Updates the subject of the e-mail.
      Parameters:
      subject - What the e-mail is about.
    • setMessage

      public void setMessage(@NonNull @NonNull String message)
      Updates the actual content of the e-mail.
      Parameters:
      message - The new content of the e-mail.
    • replaceRecipients

      public void replaceRecipients(@NonNull @NonNull Set<jakarta.mail.internet.InternetAddress> recipients) throws de.gustavblass.commons.exceptions.IllegalArgumentException
      Deletes all recipients and adds the given ones instead.
      Parameters:
      recipients - The new e-mail addresses which the e-mail shall be sent to. Must contain at least one address.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the given set is empty.
    • addRecipients

      public void addRecipients(@NonNull @NonNull Set<jakarta.mail.internet.InternetAddress> recipients) throws de.gustavblass.commons.exceptions.IllegalArgumentException
      Appends the given recipients to the already specified ones.
      Parameters:
      recipients - The new e-mail addresses which the e-mail shall be sent to. Must contain at least one address.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the given set is empty.
    • replaceCcRecipients

      public void replaceCcRecipients(@NonNull @NonNull Set<jakarta.mail.internet.InternetAddress> ccRecipients)
      Deletes all ccRecipients and adds the given ones instead.
      Parameters:
      ccRecipients - The new e-mail addresses which the e-mail shall be carbon-copied to. If no address is set, the e-mail will not be carbon-copied to anyone.
    • addCcRecipients

      public void addCcRecipients(@NonNull @NonNull Set<jakarta.mail.internet.InternetAddress> ccRecipients)
      Appends the given recipients to the already specified ones.
      Parameters:
      ccRecipients - The new e-mail addresses which the e-mail shall be carbon-copied to. If no address is set, the e-mail will still be carbon-copied to the already specified ones.
    • removeCcRecipients

      public void removeCcRecipients()
      Deletes all ccRecipients. The e-mail will not be carbon-copied to anyone.
    • replaceBccRecipients

      public void replaceBccRecipients(@NonNull @NonNull Set<jakarta.mail.internet.InternetAddress> bccRecipients)
      Deletes all bccRecipients and adds the given ones instead.
      Parameters:
      bccRecipients - The new e-mail addresses which the e-mail shall be blind-carbon-copied to. If no address is set, the e-mail will not be blind-carbon-copied to anyone.
    • addBccRecipients

      public void addBccRecipients(@NonNull @NonNull Set<jakarta.mail.internet.InternetAddress> bccRecipients)
      Appends the given recipients to the already specified ones.
      Parameters:
      bccRecipients - The new e-mail addresses which the e-mail shall be blind-carbon-copied to. If no address is set, the e-mail will still be blind-carbon-copied to the already specified ones.
    • removeBccRecipients

      public void removeBccRecipients()
      Deletes all bccRecipients. The e-mail will not be blind-carbon-copied to anyone.
    • replaceAttachments

      public void replaceAttachments(@NonNull @NonNull Set<File> attachments)
      Deletes all attachments and adds the given ones instead.
      Parameters:
      attachments - The new files which the e-mail shall be sent with. If no file is set, the e-mail will not be sent with any files.
    • addAttachments

      public void addAttachments(@NonNull @NonNull Set<File> attachments)
      Appends the given files to the already specified ones.
      Parameters:
      attachments - The new files which the e-mail shall be sent with. If no file is set, the e-mail will still be sent with the already specified ones.
    • removeAttachments

      public void removeAttachments()
      Deletes all attachments. The e-mail will not be sent with any files.
    • replacePublicKeys

      public void replacePublicKeys(@NonNull @NonNull Set<String> publicKeys)
      Deletes all publicKeys and adds the given ones instead.
      Parameters:
      publicKeys - The new PGP public keys which the e-mail shall be encrypted with. If no key is set, the e-mail will not be encrypted.
    • addPublicKeys

      public void addPublicKeys(@NonNull @NonNull Set<String> publicKeys)
      Appends the given keys to the already specified ones.
      Parameters:
      publicKeys - The new PGP public keys which the e-mail shall be encrypted with. If no key is set, the e-mail will still be encrypted with the already specified ones.
    • removePublicKeys

      public void removePublicKeys()
      Deletes all publicKeys. The e-mail will not be encrypted.
    • getRecipients

      @NonNull public @NonNull Set<jakarta.mail.internet.InternetAddress> getRecipients()
      Returns the recipients of the e-mail.
      Returns:
      Whom the e-mail shall be sent to.
    • getCcRecipients

      @NonNull public @NonNull Set<jakarta.mail.internet.InternetAddress> getCcRecipients()
      Returns the ccRecipients of the e-mail.
      Returns:
      Whom the e-mail shall be carbon-copied to.
    • getBccRecipients

      @NonNull public @NonNull Set<jakarta.mail.internet.InternetAddress> getBccRecipients()
      Returns the bccRecipients of the e-mail.
      Returns:
      Whom the e-mail shall be blind-carbon-copied to.
    • getAttachments

      @NonNull public @NonNull Set<File> getAttachments()
      Returns the attachments of the e-mail.
      Returns:
      Any number of files to send along with the message.
    • getPublicKeys

      @NonNull public @NonNull Set<String> getPublicKeys()
      Returns the publicKeys of the e-mail.
      Returns:
      Any number of PGP public keys to encrypt the message with.