Package app.YUP.externalService
Class EmailServiceImplementation
java.lang.Object
app.YUP.externalService.EmailServiceImplementation
- All Implemented Interfaces:
EmailService
This class implements the EmailService interface and provides the functionality to send emails with or without attachments.
It uses Spring's JavaMailSender to send emails.
It is annotated with @Service to indicate that it is a Spring service component.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidsendMailWithAttachment(EmailDetails details) Sends an email with an attachment.voidsendMailWithoutAttachment(EmailDetails details) Sends an email without an attachment.
-
Field Details
-
sender
The sender's email address. This is currently hardcoded to "theyupteam@gmail.com", but in a real application, it would be better to externalize this to a configuration file.
-
-
Constructor Details
-
EmailServiceImplementation
public EmailServiceImplementation()
-
-
Method Details
-
sendMailWithoutAttachment
Sends an email without an attachment. This method creates a MimeMessage, sets the sender, recipient, and subject from the provided EmailDetails, and then sends the email using the JavaMailSender.- Specified by:
sendMailWithoutAttachmentin interfaceEmailService- Parameters:
details- an EmailDetails object containing the details of the email to be sent- Throws:
EmailNotSentException- if an error occurs while sending the email
-
sendMailWithAttachment
Sends an email with an attachment. This method creates a MimeMessage, sets the sender, recipient, and subject from the provided EmailDetails, attaches the file specified in the EmailDetails, and then sends the email using the JavaMailSender.- Specified by:
sendMailWithAttachmentin interfaceEmailService- Parameters:
details- an EmailDetails object containing the details of the email to be sent, including the attachment- Throws:
EmailNotSentException- if an error occurs while sending the email
-