Class AbstractOutgoingMail

java.lang.Object
ch.tocco.nice2.messaging.mail.spi.AbstractBaseMail
ch.tocco.nice2.messaging.mail.spi.AbstractOutgoingMail
All Implemented Interfaces:
BaseMail, Mail, Cloneable
Direct Known Subclasses:
IncaMail, MailImpl

public abstract class AbstractOutgoingMail extends AbstractBaseMail implements Mail
  • Field Details

    • sourceEntity

      protected Entity sourceEntity
    • sourceEntities

      protected final Set<Entity> sourceEntities
    • recipientEntity

      protected Entity recipientEntity
    • relatedEntity

      protected Entity relatedEntity
    • expiryDate

      protected org.joda.time.LocalDate expiryDate
    • sender

      protected Entity sender
    • templateEntity

      @Nullable protected @Nullable Entity templateEntity
    • contactCategory

      @Nullable protected @Nullable Entity contactCategory
    • preventFromArchive

      protected boolean preventFromArchive
    • taskUuid

      protected UUID taskUuid
    • encodeFileNames

      protected final boolean encodeFileNames
    • charset

      protected String charset
    • attributes

      protected Map<String,Object> attributes
    • processor

      protected final MessageProcessor processor
    • persistenceService

      protected final PersistenceService persistenceService
    • mailArchive

      protected final MailArchive mailArchive
    • templateEngine

      protected final TemplateEngine templateEngine
    • nice2Template

      protected final Supplier<Nice2Template> nice2Template
    • singleCopyMail

      protected boolean singleCopyMail
    • templateAttributes

      protected Map<String,Object> templateAttributes
    • mailSendThrottle

      protected final MailSendThrottle mailSendThrottle
    • listeners

      protected Set<Mail.MailListener> listeners
  • Constructor Details

  • Method Details

    • processTemplate

      protected String processTemplate(String input) throws MailException
      Throws:
      MailException
    • processTemplateWithHtmlEscape

      protected String processTemplateWithHtmlEscape(String input) throws MailException
      Throws:
      MailException
    • processTemplate

      protected String processTemplate(String input, boolean htmlEscape) throws MailException
      Throws:
      MailException
    • getSourceEntity

      public Entity getSourceEntity()
      Specified by:
      getSourceEntity in interface Mail
    • setSourceEntity

      public Mail setSourceEntity(Entity sourceEntity)
      Specified by:
      setSourceEntity in interface Mail
    • addSourceEntity

      public Mail addSourceEntity(Entity sourceEntity)
      Set Email_archive relation to all entities in this list
      Specified by:
      addSourceEntity in interface Mail
    • getRelatedEntity

      public Entity getRelatedEntity()
      Specified by:
      getRelatedEntity in interface Mail
    • setRelatedEntity

      public Mail setRelatedEntity(Entity relatedEntity)
      Specified by:
      setRelatedEntity in interface Mail
    • getRecipientEntity

      public Entity getRecipientEntity()
      Specified by:
      getRecipientEntity in interface Mail
    • setRecipientEntity

      public Mail setRecipientEntity(Entity recipientEntity)
      Specified by:
      setRecipientEntity in interface Mail
    • addTo

      public Mail addTo(MailReceiver receiver) throws jakarta.mail.MessagingException
      Description copied from interface: Mail
      Add a receiver to "to", evaluating the right value according to the MailReceiver^s configuration.
      Specified by:
      addTo in interface Mail
      Parameters:
      receiver - the receiver
      Throws:
      jakarta.mail.MessagingException
    • addTo

      public Mail addTo(Entity userEntity) throws jakarta.mail.MessagingException
      Description copied from interface: Mail
      Add the address from a User entity to "to".
      Specified by:
      addTo in interface Mail
      Parameters:
      userEntity - Entity of type User
      Throws:
      jakarta.mail.MessagingException
    • addTo

      public Mail addTo(EntityList userEntityList) throws jakarta.mail.MessagingException
      Description copied from interface: Mail
      Add addresses from User entities to "to".
      Specified by:
      addTo in interface Mail
      Parameters:
      userEntityList - EntityList with entities of type User
      Throws:
      jakarta.mail.MessagingException
    • addCc

      public Mail addCc(Entity userEntity) throws jakarta.mail.MessagingException
      Description copied from interface: Mail
      Add the address from a User entity to "cc".
      Specified by:
      addCc in interface Mail
      Parameters:
      userEntity - Entity of type User
      Throws:
      jakarta.mail.MessagingException
    • addCc

      public Mail addCc(EntityList userEntityList) throws jakarta.mail.MessagingException
      Description copied from interface: Mail
      Add addresses from User entities to "cc".
      Specified by:
      addCc in interface Mail
      Parameters:
      userEntityList - EntityList with entities of type User
      Throws:
      jakarta.mail.MessagingException
    • addBcc

      public Mail addBcc(Entity userEntity) throws jakarta.mail.MessagingException
      Description copied from interface: Mail
      Add the address from a User entity to "bcc".
      Specified by:
      addBcc in interface Mail
      Parameters:
      userEntity - Entity of type User
      Throws:
      jakarta.mail.MessagingException
    • addBcc

      public Mail addBcc(EntityList userEntityList) throws jakarta.mail.MessagingException
      Description copied from interface: Mail
      Add addresses from User entities to "bcc".
      Specified by:
      addBcc in interface Mail
      Parameters:
      userEntityList - EntityList with entities of type User
      Throws:
      jakarta.mail.MessagingException
    • getContactCategory

      @Nullable public @Nullable Entity getContactCategory()
      Specified by:
      getContactCategory in interface Mail
    • setContactCategory

      public Mail setContactCategory(@Nullable @Nullable Entity contactCategory)
      Specified by:
      setContactCategory in interface Mail
    • setFrom

      public Mail setFrom(Entity from) throws jakarta.mail.MessagingException
      Specified by:
      setFrom in interface Mail
      Throws:
      jakarta.mail.MessagingException
    • getSender

      public Entity getSender()
      Specified by:
      getSender in interface Mail
    • setSender

      public Mail setSender(Entity sender)
      Specified by:
      setSender in interface Mail
    • setSingleCopyMail

      public Mail setSingleCopyMail(boolean singleCopyMail)
      Description copied from interface: Mail
      only relevant for the GUI MailAction (defaults to false), won't link the resulting MailArchive entity to the recipient but the User(s) with the email address in BaseMail.getCc().
      Specified by:
      setSingleCopyMail in interface Mail
      Parameters:
      singleCopyMail - true / false
    • isSingleCopyMail

      public boolean isSingleCopyMail()
      Specified by:
      isSingleCopyMail in interface Mail
    • getTemplateEntity

      @Nullable public @Nullable Entity getTemplateEntity()
      Specified by:
      getTemplateEntity in interface Mail
    • setTemplateEntity

      public Mail setTemplateEntity(@Nullable @Nullable Entity templateEntity)
      Specified by:
      setTemplateEntity in interface Mail
    • setTemplateAttribute

      public Mail setTemplateAttribute(String name, Object value)
      Description copied from interface: Mail
      Set a template attribute. If an attribute with the same name already exists it will be overriden. To set entity data into a variable use Mail.setTemplateEntityData(String, ch.tocco.nice2.persist.entity.Entity) and Mail.setTemplateEntityListData(String, ch.tocco.nice2.persist.entity.EntityList).
      Specified by:
      setTemplateAttribute in interface Mail
      Parameters:
      name - The name for the attribute.
      value - The value.
    • setTemplateEntityData

      public Mail setTemplateEntityData(String name, Entity entity)
      Description copied from interface: Mail
      Set an entity template attribute
      Specified by:
      setTemplateEntityData in interface Mail
      Parameters:
      name - the name for the attribute
      entity - the entity
    • setTemplateEntityListData

      public Mail setTemplateEntityListData(String name, EntityList entityList)
      Description copied from interface: Mail
      Set an entity list template attribute
      Specified by:
      setTemplateEntityListData in interface Mail
      Parameters:
      name - the name for the attribute
      entityList - the entity list
    • getTemplateAttribute

      public Optional<Object> getTemplateAttribute(String name)
      Description copied from interface: Mail
      Get the value of a template attribute.
      Specified by:
      getTemplateAttribute in interface Mail
      Parameters:
      name - The name of the attribute to get.
      Returns:
      the value or Optional.empty() if it's not set.
    • getTemplateAttributes

      public Map<String,Object> getTemplateAttributes()
      Description copied from interface: Mail
      Get an unmodifiable map of all template attributes.
      Specified by:
      getTemplateAttributes in interface Mail
      Returns:
      an unmodifiable map of all attributes.
    • preventFromArchive

      public Mail preventFromArchive(boolean preventFromArchive)
      Specified by:
      preventFromArchive in interface Mail
    • getCharset

      public String getCharset()
    • setCharset

      public void setCharset(String charset)
    • getAttributes

      public Map<String,Object> getAttributes()
      Specified by:
      getAttributes in interface Mail
    • getExpiryDate

      public org.joda.time.LocalDate getExpiryDate()
      Specified by:
      getExpiryDate in interface Mail
    • setExpiryDate

      public Mail setExpiryDate(org.joda.time.LocalDate expiryDate)
      Specified by:
      setExpiryDate in interface Mail
    • getTaskUuid

      public UUID getTaskUuid()
      Specified by:
      getTaskUuid in interface Mail
    • setTaskUuid

      public Mail setTaskUuid(UUID taskUuid)
      Description copied from interface: Mail
      Set the UUID which is needed to group the mails sent from the same task
      Specified by:
      setTaskUuid in interface Mail
      Parameters:
      taskUuid - a random uuid given from the task which sends the mail
    • checkRecipientAndContent

      protected void checkRecipientAndContent() throws MailException, jakarta.mail.MessagingException
      Throws:
      MailException
      jakarta.mail.MessagingException
    • send

      public void send() throws MailException
      Description copied from interface: Mail
      Send the message.
      Specified by:
      send in interface Mail
      Throws:
      MailException
    • doSend

      protected abstract MailArchive.MailArchiveEntry doSend() throws MailException
      Throws:
      MailException
    • clone

      public Mail clone() throws CloneNotSupportedException
      Specified by:
      clone in interface Mail
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • addCc

      public void addCc(String addresses)
      Description copied from interface: BaseMail
      Add addresses from a String to "cc".
      Can be either only email or email and name in format: "firstname lastname <email>.
      example: "Hans Meier <hmeier@tocco.ch>"
      Specified by:
      addCc in interface BaseMail
      Overrides:
      addCc in class AbstractBaseMail
      Parameters:
      addresses - String separated with "," or "\n"
    • addBcc

      public void addBcc(String addresses)
      Description copied from interface: BaseMail
      Add addresses from a String to "bcc".
      Can be either only email or email and name in format: "firstname lastname <email>.
      example: "Hans Meier <hmeier@tocco.ch>"
      Specified by:
      addBcc in interface BaseMail
      Overrides:
      addBcc in class AbstractBaseMail
      Parameters:
      addresses - String separated with "," or "\n"
    • addMailListener

      public void addMailListener(Mail.MailListener listener)
      Specified by:
      addMailListener in interface Mail
    • removeMailListener

      public void removeMailListener(Mail.MailListener listener)
      Specified by:
      removeMailListener in interface Mail