Update EmailService.java

This commit is contained in:
Ludy87 2025-05-20 22:10:40 +02:00
parent 9504b359cc
commit bc9af64372
No known key found for this signature in database
GPG Key ID: 92696155E0220F94

View File

@ -37,8 +37,21 @@ public class EmailService {
*/ */
@Async @Async
public void sendEmailWithAttachment(Email email) throws MessagingException { public void sendEmailWithAttachment(Email email) throws MessagingException {
ApplicationProperties.Mail mailProperties = applicationProperties.getMail();
MultipartFile file = email.getFileInput(); MultipartFile file = email.getFileInput();
// 1) Validate recipient email address
if (email.getTo() == null || email.getTo().trim().isEmpty()) {
throw new MessagingException("Invalid Addresses");
}
// 2) Validate attachment
if (file == null
|| file.isEmpty()
|| file.getOriginalFilename() == null
|| file.getOriginalFilename().isEmpty()) {
throw new MessagingException("An attachment is required to send the email.");
}
ApplicationProperties.Mail mailProperties = applicationProperties.getMail();
// Creates a MimeMessage to represent the email // Creates a MimeMessage to represent the email
MimeMessage message = mailSender.createMimeMessage(); MimeMessage message = mailSender.createMimeMessage();