Class MailSenderService

java.lang.Object
best.skn.mail.services.MailSenderService
All Implemented Interfaces:
MailSenderInterface

@Service public class MailSenderService extends Object implements MailSenderInterface
Mail Sender Service Class
Since:
2024-03-07
Version:
1.2.2
Author:
SKN
Use Case:
Spring Boot Reactive
Dedicated To:
Trina, Logno and Atoshi
  • Field Details

    • mailSender

      @Autowired private org.springframework.mail.javamail.JavaMailSender mailSender
      Private Java Mail Sender object
      Since:
      v1.0.0
    • templateEngine

      @Autowired private org.thymeleaf.TemplateEngine templateEngine
      private Thymeleaf Template Engine object
      Since:
      v1.0.0
  • Constructor Details

    • MailSenderService

      public MailSenderService()
  • Method Details

    • sendMail

      public reactor.core.publisher.Mono<String> sendMail(String from, String to, String subject, String body) throws jakarta.mail.MessagingException
      Description copied from interface: MailSenderInterface
      Method to send basic mail
      Specified by:
      sendMail in interface MailSenderInterface
      Parameters:
      from - a String which must be a valid email address from whom the mail will be sent
      to - a String which must be a valid email address to whom the mail will be sent
      subject - a String containing the subject of the mail
      body - a String containing the main body of the mail
      Returns:
      a Mono of String as a response
      Throws:
      jakarta.mail.MessagingException - a messaging exception if the mail is not sent successfully
    • sendMailWithAttachment

      public reactor.core.publisher.Mono<String> sendMailWithAttachment(String from, String to, String subject, String body, String filePath) throws jakarta.mail.MessagingException
      Description copied from interface: MailSenderInterface
      Method to send basic mail with attachment
      Specified by:
      sendMailWithAttachment in interface MailSenderInterface
      Parameters:
      from - a String which must be a valid email address from whom the mail will be sent
      to - a String which must be a valid email address to whom the mail will be sent
      subject - a String containing the subject of the mail
      body - a String containing the main body of the mail
      filePath - a String containing the file path to the attachment
      Returns:
      a Mono of String as a response
      Throws:
      jakarta.mail.MessagingException - a messaging exception if the mail is not sent successfully
    • sendMailWithHtmlTemplate

      public reactor.core.publisher.Mono<String> sendMailWithHtmlTemplate(String from, String to, String subject, String templateName, org.thymeleaf.context.Context context) throws jakarta.mail.MessagingException
      Description copied from interface: MailSenderInterface
      Method to send mail with HTML template
      Specified by:
      sendMailWithHtmlTemplate in interface MailSenderInterface
      Parameters:
      from - a String which must be a valid email address from whom the mail will be sent
      to - a String which must be a valid email address to whom the mail will be sent
      subject - a String containing the subject of the mail
      templateName - a String containing the template name for the HTML template
      context - a Thymeleaf Context for the HTML template
      Returns:
      a Mono of String as a response
      Throws:
      jakarta.mail.MessagingException - a messaging exception if the mail is not sent successfully
    • sendMailWithHtmlTemplateAndAttachment

      public reactor.core.publisher.Mono<String> sendMailWithHtmlTemplateAndAttachment(String from, String to, String subject, String templateName, org.thymeleaf.context.Context context, String filePath) throws jakarta.mail.MessagingException
      Description copied from interface: MailSenderInterface
      Method to send mail with HTML template and attachment
      Specified by:
      sendMailWithHtmlTemplateAndAttachment in interface MailSenderInterface
      Parameters:
      from - a String which must be a valid email address from whom the mail will be sent
      to - a String which must be a valid email address to whom the mail will be sent
      subject - a String containing the subject of the mail
      templateName - a String containing the template name for the HTML template
      context - a Thymeleaf Context for the HTML template
      filePath - a String containing the file path to the attachment
      Returns:
      a Mono of String as a response
      Throws:
      jakarta.mail.MessagingException - a messaging exception if the mail is not sent successfully