Skip to content

Commit

Permalink
CNDE - 1928 add the logic to handle muliple email address
Browse files Browse the repository at this point in the history
  • Loading branch information
jayasudhasundaram committed Dec 6, 2024
1 parent 7b88671 commit 73af3ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import software.amazon.awssdk.services.ses.model.*;

import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
Expand All @@ -30,6 +31,9 @@ public class EmailService {
@Value("${aws.ses.source-email}")
private String sourceEmail;

@Value("${aws.ses.recipient-emails}")
private String recipientEmails;

@Value("${aws.s3.bucket-name}")
private String bucketName;

Expand Down Expand Up @@ -89,8 +93,7 @@ public void sendComparisonEmail(EmailEventModel emailEvent) {
SendEmailRequest request = SendEmailRequest.builder()
.source(sourceEmail) // Sender's email
.destination(Destination.builder()
// TODO: REPLACE WITH ENVIRONMENT VARIABLE, something like RECIPIENT_EMAIL: {LIST of email such as "email1, email2, etc..."}
.toAddresses("[email protected]") // Add recipient emails here
.toAddresses(getRecipientEmailList())
.build())
.message(Message.builder()
.subject(Content.builder()
Expand Down Expand Up @@ -142,4 +145,24 @@ private String buildEmailContent(EmailEventModel event, String reportUrl) {

return content.toString();
}

private List<String> getRecipientEmailList() {
if (recipientEmails == null || recipientEmails.trim().isEmpty()) {
log.error("No recipient emails configured");
throw new IllegalStateException("No recipient emails configured");
}

List<String> emailList = Arrays.stream(recipientEmails.split(","))
.map(String::trim)
.filter(email -> !email.isEmpty())
.collect(Collectors.toList());

if (emailList.isEmpty()) {
log.error("No valid recipient emails found after parsing");
throw new IllegalStateException("No valid recipient emails found after parsing");
}

log.debug("Processed {} recipient email(s)", emailList.size());
return emailList;
}
}
2 changes: 2 additions & 0 deletions DataCompareESender/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ aws:
url-expiration-hours: 48
ses:
source-email: [email protected]
recipient-emails: ${RECIPIENT_EMAILS}

0 comments on commit 73af3ed

Please sign in to comment.