-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid hardcoded emails on notification listener.
- Loading branch information
Showing
4 changed files
with
19 additions
and
5 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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.core.listener.JobExecutionListenerSupport; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
|
||
|
@@ -11,14 +12,20 @@ public class JobCompletionNotificationListener extends JobExecutionListenerSuppo | |
@Autowired | ||
private JavaMailSender mailSender; | ||
|
||
private String notificationEmail; | ||
|
||
public JobCompletionNotificationListener(String notificationEmail) { | ||
this.notificationEmail = notificationEmail; | ||
} | ||
|
||
@Override | ||
public void afterJob(JobExecution jobExecution) { | ||
|
||
SimpleMailMessage message = new SimpleMailMessage(); | ||
|
||
message.setSubject("Job completion"); | ||
message.setFrom("[email protected]"); | ||
message.setTo("[email protected]"); | ||
message.setFrom(notificationEmail); | ||
message.setTo(notificationEmail); | ||
message.setText("Job completed with " + jobExecution.getExitStatus()); | ||
|
||
mailSender.send(message); | ||
|
@@ -30,8 +37,8 @@ public void beforeJob(JobExecution jobExecution) { | |
SimpleMailMessage message = new SimpleMailMessage(); | ||
|
||
message.setSubject("Job started"); | ||
message.setFrom("[email protected]"); | ||
message.setTo("[email protected]"); | ||
message.setFrom(notificationEmail); | ||
message.setTo(notificationEmail); | ||
message.setText("Job started"); | ||
|
||
mailSender.send(message); | ||
|
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
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