Class MailUtil

java.lang.Object
jp.ecuacion.lib.core.util.MailUtil

public class MailUtil extends Object
Provides mail-related utility methods.
  • Constructor Details

    • MailUtil

      public MailUtil()
      Constructs a new instance.
  • Method Details

    • sendErrorMail

      public void sendErrorMail(@Nonnull Throwable throwable)
      Sends an error mail.

      This is used in exception handler to notify system administrator the occurence of an error.

      The mail is sent to the addresses defined in application.properties with key jp.ecuacion.lib.core.mail.address-csv-on-system-error.

      Parameters:
      throwable - throwable
    • sendErrorMail

      public void sendErrorMail(@Nonnull Throwable throwable, @Nullable String additionalMessage)
      Sends an error mail adding an additional message to it.
      Parameters:
      throwable - throwable.
      additionalMessage - additional message, may be null if no additionalMessage is needed. In the case of null no additional message is output.
    • sendWarnMail

      public void sendWarnMail(@Nullable String content, @Nonnull List<String> mailToList)
      Sends a warn mail.
      Parameters:
      content - content, may be null if no mailbody content needed.
      mailToList - list of mailadresses used for "TO" address
    • sendMail

      public void sendMail(@Nullable List<String> mailToList, @Nullable List<String> mailCcList, @Nonnull String title, @Nullable String content) throws Exception
      Provides the mail-sending function.

      The following settings ars needed to application.properties to send mails with this object.

       # true or false
       SMTP_AUTHENTICATION=true
       #Normally "true" if the port number is 465, "false" if 587
       SMTP_SSL_ENABLED=true
       jp.ecuacion.lib.core.mail.smtp.server=smtp.gmail.com
       jp.ecuacion.lib.core.mail.smtp.port=465
       jp.ecuacion.lib.core.mail.smtp.sender=info@ecuacion.jp
       jp.ecuacion.lib.core.mail.smtp.password=(password)
       jp.ecuacion.lib.core.mail.title-prefix=[app-name: staging environment]
       jp.ecuacion.lib.core.mail.address-csv-on-system-error=info@ecuacion.jp
       
      Parameters:
      mailToList - mailToList. Either mailToList or mailCcList need to have at least one element.
      mailCcList - mailCcList. Either mailToList or mailCcList need to have at least one element.
      title - title
      content - content, may be null if no content needed.
      Throws:
      Exception - Exception