Class MailService

java.lang.Object
de.bytestore.hostinger.security.service.MailService

@Service @Component public class MailService extends Object
  • Constructor Details

    • MailService

      public MailService(io.jmix.core.DataManager dataManager, freemarker.template.Configuration freeMarkerConfiguration, org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer freeMarkerConfigurer, io.jmix.core.security.SystemAuthenticator systemAuthenticator, io.jmix.core.UnconstrainedDataManager unconstrainedDataManager)
  • Method Details

    • onApplicationStarted

      @EventListener public void onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event)
    • sendMail

      public void sendMail(@Email @Email String receiverIO, String templateIO, HashMap<String,Object> dataIO) throws freemarker.template.TemplateException, IOException
      Sends an email based on a specified template and data map.
      Parameters:
      receiverIO - The email address of the recipient. Must be a valid email format.
      templateIO - The name or identifier of the email template to use.
      dataIO - A map containing key-value pairs to be used to populate the template.
      Throws:
      freemarker.template.TemplateException
      IOException
    • sendMail

      public void sendMail(@Email @Email String receiverIO, String templateIO, HashMap<String,Object> dataIO, String[] bccIO, String[] ccIO) throws freemarker.template.TemplateException, IOException
      Sends an email using the specified template and data.
      Parameters:
      receiverIO - The email address of the primary recipient.
      templateIO - The email template to be used for the mail content.
      dataIO - A hashmap containing dynamic data to be used in the email template.
      bccIO - An array of email addresses to be included in the BCC field.
      ccIO - An array of email addresses to be included in the CC field.
      Throws:
      freemarker.template.TemplateException - If there is an error in processing the email template.
      IOException - If there is an input-output error during email sending.
    • getSubject

      public String getSubject(String templateIO)
      Generates the subject line for an email.
      Parameters:
      templateIO - The name or identifier of the email template.
      Returns:
      A string representing the subject of the email.
    • parseTemplate

      public String parseTemplate(String templateIO, HashMap<String,Object> dataIO) throws IOException, freemarker.template.TemplateException
      Parses the given template using the provided data map.
      Parameters:
      templateIO - the identifier for the template
      dataIO - the map containing template data
      Returns:
      the parsed template as a string
      Throws:
      IOException - if an I/O error occurs during template processing
      freemarker.template.TemplateException - if an error occurs while rendering the template
    • getSender

      public MailTemplateSender getSender(String templateIO)
      Retrieves a MailTemplateSender based on the provided templateIO identifier.
      Parameters:
      templateIO - the identifier of the MailTemplateSender to be retrieved
      Returns:
      the MailTemplateSender associated with the given templateIO
    • sendMail

      public void sendMail(@Email @Email String receiverIO, MailAccount senderIO, String contentIO, String subjectIO, String[] bccIO, String[] ccIO) throws RuntimeException
      Sends an email using the specified parameters.
      Parameters:
      receiverIO - The email address of the recipient.
      senderIO - The sender's mail account information.
      contentIO - The content of the email.
      subjectIO - The subject of the email.
      bccIO - An array of email addresses to be added as BCC (Blind Carbon Copy) recipients.
      ccIO - An array of email addresses to be added as CC (Carbon Copy) recipients.
      Throws:
      RuntimeException
    • getMailAccounts

      public List<MailAccount> getMailAccounts()
      Retrieves all mail accounts.
      Returns:
      A list of MailAccounts objects representing all mail accounts in the system.
    • getTemplateSenders

      public List<MailTemplateSender> getTemplateSenders()
      Retrieves all mail template senders.
      Returns:
      A list of MailTemplateSender objects representing all mail template senders in the system.
    • testMailAccount

      public void testMailAccount(MailAccount accountIO) throws jakarta.mail.MessagingException
      Tests the given mail account by attempting to establish a connection using its settings.
      Parameters:
      accountIO - the mail account information to be tested, including server settings and credentials
      Throws:
      jakarta.mail.MessagingException - if a connection to the mail server cannot be established
    • listTemplates

      public List<String> listTemplates() throws IOException
      Retrieves a list of mail template filenames available in the classpath.
      Returns:
      a List of template filenames found in the specified classpath directory.
      Throws:
      IOException - if an I/O error occurs while accessing the templates.