Skip to content

Commit

Permalink
Only use one mailbox bean
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Nov 4, 2023
1 parent 4261625 commit 692dcce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions myconext-server/src/main/java/myconext/mail/MailConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 692dcce

Please sign in to comment.