diff --git a/myconext-server/src/main/java/myconext/mail/MailConfiguration.java b/myconext-server/src/main/java/myconext/mail/MailConfiguration.java index 37e69f90..ebc1ab43 100644 --- a/myconext-server/src/main/java/myconext/mail/MailConfiguration.java +++ b/myconext-server/src/main/java/myconext/mail/MailConfiguration.java @@ -9,7 +9,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Profile; +import org.springframework.core.env.Profiles; import org.springframework.core.env.Environment; import org.springframework.core.io.Resource; import org.springframework.mail.javamail.JavaMailSender; @@ -47,19 +47,15 @@ public class MailConfiguration { @Autowired private EmailsSendRepository emailsSendRepository; + @Autowired + private Environment environment; + @Bean - @Profile({"!dev"}) public MailBox mailSenderProd() throws IOException { + if (environment.acceptsProfiles(Profiles.of("dev", "test", "shib"))) { + return new MockMailBox(mailSender, emailFrom, magicLinkUrl, mySURFconextURL, loginSURFconextURL, objectMapper, mailTemplatesDirectory, emailsSendRepository, environment); + } return new MailBox(mailSender, emailFrom, magicLinkUrl, mySURFconextURL, loginSURFconextURL, objectMapper, mailTemplatesDirectory, emailsSendRepository, emailSpamThresholdSeconds); } - - @Bean - @Profile({"dev", "test", "shib"}) - @Primary - public MailBox mailSenderDev(Environment environment) throws IOException { - return new MockMailBox(mailSender, emailFrom, magicLinkUrl, mySURFconextURL, loginSURFconextURL, objectMapper, mailTemplatesDirectory, emailsSendRepository, environment); - } - - } diff --git a/myconext-server/src/main/java/myconext/mail/MockMailBox.java b/myconext-server/src/main/java/myconext/mail/MockMailBox.java index ce9dfb00..6df00cb9 100644 --- a/myconext-server/src/main/java/myconext/mail/MockMailBox.java +++ b/myconext-server/src/main/java/myconext/mail/MockMailBox.java @@ -31,7 +31,7 @@ protected void doSendMail(MimeMessage message) { @Override protected void setText(String html, String text, MimeMessageHelper helper) { String osName = System.getProperty("os.name").toLowerCase(); - if (osName.contains("mac os x") && false && !env.acceptsProfiles(Profiles.of("test"))) { + if (osName.contains("mac os x") && !env.acceptsProfiles(Profiles.of("test"))) { openInBrowser(html); } }