generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CNDE - 1928 add the logic to handle muliple email address
- Loading branch information
1 parent
7b88671
commit 73af3ed
Showing
2 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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; | ||
|
||
|
@@ -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() | ||
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ aws: | |
url-expiration-hours: 48 | ||
ses: | ||
source-email: [email protected] | ||
recipient-emails: ${RECIPIENT_EMAILS} | ||
|