Class MailService
java.lang.Object
de.bytestore.hostinger.security.service.MailService
-
Constructor Summary
ConstructorsConstructorDescriptionMailService(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 Summary
Modifier and TypeMethodDescriptionRetrieves all mail accounts.Retrieves a MailTemplateSender based on the provided templateIO identifier.getSubject(String templateIO) Generates the subject line for an email.Retrieves all mail template senders.Retrieves a list of mail template filenames available in the classpath.voidonApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) parseTemplate(String templateIO, HashMap<String, Object> dataIO) Parses the given template using the provided data map.voidsendMail(@Email String receiverIO, MailAccount senderIO, String contentIO, String subjectIO, String[] bccIO, String[] ccIO) Sends an email using the specified parameters.voidSends an email based on a specified template and data map.voidsendMail(@Email String receiverIO, String templateIO, HashMap<String, Object> dataIO, String[] bccIO, String[] ccIO) Sends an email using the specified template and data.voidtestMailAccount(MailAccount accountIO) Tests the given mail account by attempting to establish a connection using its settings.
-
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, IOExceptionSends 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.TemplateExceptionIOException
-
sendMail
public void sendMail(@Email @Email String receiverIO, String templateIO, HashMap<String, Object> dataIO, String[] bccIO, String[] ccIO) throws freemarker.template.TemplateException, IOExceptionSends 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
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.TemplateExceptionParses the given template using the provided data map.- Parameters:
templateIO- the identifier for the templatedataIO- the map containing template data- Returns:
- the parsed template as a string
- Throws:
IOException- if an I/O error occurs during template processingfreemarker.template.TemplateException- if an error occurs while rendering the template
-
getSender
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
Retrieves all mail accounts.- Returns:
- A list of MailAccounts objects representing all mail accounts in the system.
-
getTemplateSenders
Retrieves all mail template senders.- Returns:
- A list of MailTemplateSender objects representing all mail template senders in the system.
-
testMailAccount
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
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.
-