#120 add debug email

This commit is contained in:
Anton Romanov 2019-05-25 21:15:21 +04:00
parent 477a9fd6ff
commit 916bbae414
3 changed files with 21 additions and 3 deletions

View File

@ -21,6 +21,8 @@ public class ApplicationProperties {
private boolean checkRun; private boolean checkRun;
private String debugEmail;
public boolean isUseHttps() { public boolean isUseHttps() {
return useHttps; return useHttps;
} }
@ -60,4 +62,12 @@ public class ApplicationProperties {
public void setCheckRun(boolean checkRun) { public void setCheckRun(boolean checkRun) {
this.checkRun = checkRun; this.checkRun = checkRun;
} }
public String getDebugEmail() {
return debugEmail;
}
public void setDebugEmail(String debugEmail) {
this.debugEmail = debugEmail;
}
} }

View File

@ -1,5 +1,6 @@
package ru.ulstu.user.service; package ru.ulstu.user.service;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.mail.MailProperties; import org.springframework.boot.autoconfigure.mail.MailProperties;
@ -21,11 +22,9 @@ import java.util.Map;
@Service @Service
public class MailService { public class MailService {
private final Logger log = LoggerFactory.getLogger(MailService.class);
private static final String USER = "user"; private static final String USER = "user";
private static final String BASE_URL = "baseUrl"; private static final String BASE_URL = "baseUrl";
private final Logger log = LoggerFactory.getLogger(MailService.class);
private final JavaMailSender javaMailSender; private final JavaMailSender javaMailSender;
private final SpringTemplateEngine templateEngine; private final SpringTemplateEngine templateEngine;
private final MailProperties mailProperties; private final MailProperties mailProperties;
@ -48,10 +47,18 @@ public class MailService {
message.setFrom(mailProperties.getUsername()); message.setFrom(mailProperties.getUsername());
message.setSubject(subject); message.setSubject(subject);
message.setText(content, true); message.setText(content, true);
modifyForDebug(message, subject);
javaMailSender.send(mimeMessage); javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to); log.debug("Sent email to User '{}'", to);
} }
private void modifyForDebug(MimeMessageHelper message, String originalSubject) throws MessagingException {
if (!StringUtils.isEmpty(applicationProperties.getDebugEmail())) {
message.setTo(applicationProperties.getDebugEmail());
message.setSubject("To " + applicationProperties.getDebugEmail() + "; " + originalSubject);
}
}
@Async @Async
public void sendEmailFromTemplate(User user, String templateName, String subject) { public void sendEmailFromTemplate(User user, String templateName, String subject) {
Context context = new Context(); Context context = new Context();

View File

@ -35,5 +35,6 @@ liquibase.change-log=classpath:db/changelog-master.xml
ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.base-url=http://127.0.0.1:8080
ng-tracker.undead-user-login=admin ng-tracker.undead-user-login=admin
ng-tracker.dev-mode=true ng-tracker.dev-mode=true
ng-tracker.debug_email=romanov73@gmail.com
ng-tracker.use-https=false ng-tracker.use-https=false
ng-tracker.check-run=false ng-tracker.check-run=false