diff --git a/notifier/smtp/src/main/java/com/epam/pipeline/notifier/service/task/SMTPNotificationManager.java b/notifier/smtp/src/main/java/com/epam/pipeline/notifier/service/task/SMTPNotificationManager.java index 59c5630777..69c87190c5 100644 --- a/notifier/smtp/src/main/java/com/epam/pipeline/notifier/service/task/SMTPNotificationManager.java +++ b/notifier/smtp/src/main/java/com/epam/pipeline/notifier/service/task/SMTPNotificationManager.java @@ -148,7 +148,7 @@ private Optional buildEmail(NotificationMessage message) throws EmailExce } String userEmail = getTargetUserEmail(message); - if (userEmail != null) { + if (isValidEmail(userEmail)) { email.addTo(userEmail); } @@ -156,7 +156,7 @@ private Optional buildEmail(NotificationMessage message) throws EmailExce for (PipelineUser user : keepInformedUsers) { String address = user.getEmail(); - if (address != null) { + if (isValidEmail(address)) { email.addBcc(address); } } @@ -197,4 +197,8 @@ private void sleepIfRequired(final long delay) { } } + private boolean isValidEmail(final String email) { + return EmailValidator.getInstance().isValid(email); + } + }