Class EmailService

java.lang.Object
springboot.bg.harisauto.email.EmailService

@Service public class EmailService extends Object
Feedback.java - Entity class for Feedback.
Author:
Kristian Popov
  • Constructor Details

    • EmailService

      @Autowired public EmailService(org.springframework.mail.javamail.JavaMailSender javaMailSender, org.thymeleaf.TemplateEngine templateEngine)
  • Method Details

    • sendGreetingEmail

      @Async @EventListener public void sendGreetingEmail(UserRegisteredEvent event) throws jakarta.mail.MessagingException
      Sends a plain text email to the user upon registration.
      Parameters:
      event - The event containing the user's email address.
      Throws:
      jakarta.mail.MessagingException - If the email could not be sent.
    • sendInvoiceEmail

      @Async public void sendInvoiceEmail(String to, byte[] pdfBytes, String invoiceNumber)
      Sends the generated invoice to the customer with the PDF attached.

      Delivery failures are logged rather than propagated, so that a failing mail server never rolls back an invoice that was already persisted.

      Parameters:
      to - The customer's email address.
      pdfBytes - The rendered invoice PDF.
      invoiceNumber - The invoice number, used for the subject and attachment name.
    • sendDailyReport

      @Async public void sendDailyReport(long totalUsers, long newUsers, long totalInvoices)
      Sends the daily summary report to the configured administrator address.

      Delivery failures are logged rather than propagated, so that a failing mail server never aborts the scheduled job.

      Parameters:
      totalUsers - Total number of registered users.
      newUsers - Users registered in the last 24 hours.
      totalInvoices - Total number of invoices issued.
    • sendTwoFactorCode

      public void sendTwoFactorCode(String to, String code, int expiryMinutes)
      Sends a one-time sign-in code.

      Unlike the other mail here, delivery failures are not swallowed. If the code never arrives the user cannot sign in, so the caller has to know: it refuses the sign-in rather than leaving them stuck on a code that was never sent. This also runs synchronously for the same reason.

      Parameters:
      to - The user's email address.
      code - The six-digit code.
      expiryMinutes - How long the code stays valid.