@Test public void testWithDefaultFrom() throws Exception { SmtpConfigDto configDto = ImmutableSmtpConfigDto.builder() .host("localhost") .username("") .passwordExists(false) .fromEmailAddress("") .fromDisplayName("From Example") .version("1234") .testEmailRecipient("to@example.org") .build(); adminJsonService.sendTestEmail(configDto); Message message = mailService.getMessage(); String localHostname = InetAddress.getLocalHost().getHostName(); assertThat(message.getFrom()[0].toString()) .isEqualTo("From Example <glowroot@" + localHostname + ">"); assertThat(message.getRecipients(Message.RecipientType.TO)[0].toString()) .isEqualTo("to@example.org"); assertThat(message.getSubject()).isEqualTo("[Glowroot] Test email"); assertThat(message.getContent()).isEqualTo(""); }
@POST(path = "/backend/admin/send-test-email", permission = "admin:edit:smtp") String sendTestEmail(@BindRequest SmtpConfigDto configDto) throws IOException { SmtpConfigDto configDtoWithoutNewPassword; String passwordOverride; String newPassword = configDto.newPassword(); if (newPassword.isEmpty()) { configDtoWithoutNewPassword = configDto; passwordOverride = null; } else { configDtoWithoutNewPassword = ImmutableSmtpConfigDto.builder() .copyFrom(configDto) .newPassword("") .build(); passwordOverride = newPassword; } String testEmailRecipient = configDtoWithoutNewPassword.testEmailRecipient(); checkNotNull(testEmailRecipient); List<String> emailAddresses = Splitter.on(',').trimResults().splitToList(testEmailRecipient); try { String centralDisplay; String agentDisplay; if (central) { centralDisplay = configRepository.getCentralAdminGeneralConfig().centralDisplayName(); agentDisplay = ""; } else { centralDisplay = ""; agentDisplay = configRepository.getEmbeddedAdminGeneralConfig() .agentDisplayNameOrDefault(); } String subject = "Test email"; AlertingService.sendEmail(centralDisplay, agentDisplay, subject, emailAddresses, "", configDtoWithoutNewPassword.convert(configRepository), passwordOverride, configRepository.getLazySecretKey(), mailService); } catch (Exception e) { logger.debug(e.getMessage(), e); return createErrorResponse(e.toString()); } return "{}"; }
AdminJsonService { @POST(path = "/backend/admin/send-test-email", permission = "admin:edit:smtp") String sendTestEmail(@BindRequest SmtpConfigDto configDto) throws IOException { SmtpConfigDto configDtoWithoutNewPassword; String passwordOverride; String newPassword = configDto.newPassword(); if (newPassword.isEmpty()) { configDtoWithoutNewPassword = configDto; passwordOverride = null; } else { configDtoWithoutNewPassword = ImmutableSmtpConfigDto.builder() .copyFrom(configDto) .newPassword("") .build(); passwordOverride = newPassword; } String testEmailRecipient = configDtoWithoutNewPassword.testEmailRecipient(); checkNotNull(testEmailRecipient); List<String> emailAddresses = Splitter.on(',').trimResults().splitToList(testEmailRecipient); try { String centralDisplay; String agentDisplay; if (central) { centralDisplay = configRepository.getCentralAdminGeneralConfig().centralDisplayName(); agentDisplay = ""; } else { centralDisplay = ""; agentDisplay = configRepository.getEmbeddedAdminGeneralConfig() .agentDisplayNameOrDefault(); } String subject = "Test email"; AlertingService.sendEmail(centralDisplay, agentDisplay, subject, emailAddresses, "", configDtoWithoutNewPassword.convert(configRepository), passwordOverride, configRepository.getLazySecretKey(), mailService); } catch (Exception e) { logger.debug(e.getMessage(), e); return createErrorResponse(e.toString()); } return "{}"; } }
AdminJsonService { @POST(path = "/backend/admin/send-test-email", permission = "admin:edit:smtp") String sendTestEmail(@BindRequest SmtpConfigDto configDto) throws IOException { SmtpConfigDto configDtoWithoutNewPassword; String passwordOverride; String newPassword = configDto.newPassword(); if (newPassword.isEmpty()) { configDtoWithoutNewPassword = configDto; passwordOverride = null; } else { configDtoWithoutNewPassword = ImmutableSmtpConfigDto.builder() .copyFrom(configDto) .newPassword("") .build(); passwordOverride = newPassword; } String testEmailRecipient = configDtoWithoutNewPassword.testEmailRecipient(); checkNotNull(testEmailRecipient); List<String> emailAddresses = Splitter.on(',').trimResults().splitToList(testEmailRecipient); try { String centralDisplay; String agentDisplay; if (central) { centralDisplay = configRepository.getCentralAdminGeneralConfig().centralDisplayName(); agentDisplay = ""; } else { centralDisplay = ""; agentDisplay = configRepository.getEmbeddedAdminGeneralConfig() .agentDisplayNameOrDefault(); } String subject = "Test email"; AlertingService.sendEmail(centralDisplay, agentDisplay, subject, emailAddresses, "", configDtoWithoutNewPassword.convert(configRepository), passwordOverride, configRepository.getLazySecretKey(), mailService); } catch (Exception e) { logger.debug(e.getMessage(), e); return createErrorResponse(e.toString()); } return "{}"; } AdminJsonService(boolean central, boolean offlineViewer, File confDir,
            @Nullable File sharedConfDir, ConfigRepository configRepository, RepoAdmin repoAdmin,
            LiveAggregateRepository liveAggregateRepository, MailService mailService,
            HttpClient httpClient); }
AdminJsonService { @POST(path = "/backend/admin/send-test-email", permission = "admin:edit:smtp") String sendTestEmail(@BindRequest SmtpConfigDto configDto) throws IOException { SmtpConfigDto configDtoWithoutNewPassword; String passwordOverride; String newPassword = configDto.newPassword(); if (newPassword.isEmpty()) { configDtoWithoutNewPassword = configDto; passwordOverride = null; } else { configDtoWithoutNewPassword = ImmutableSmtpConfigDto.builder() .copyFrom(configDto) .newPassword("") .build(); passwordOverride = newPassword; } String testEmailRecipient = configDtoWithoutNewPassword.testEmailRecipient(); checkNotNull(testEmailRecipient); List<String> emailAddresses = Splitter.on(',').trimResults().splitToList(testEmailRecipient); try { String centralDisplay; String agentDisplay; if (central) { centralDisplay = configRepository.getCentralAdminGeneralConfig().centralDisplayName(); agentDisplay = ""; } else { centralDisplay = ""; agentDisplay = configRepository.getEmbeddedAdminGeneralConfig() .agentDisplayNameOrDefault(); } String subject = "Test email"; AlertingService.sendEmail(centralDisplay, agentDisplay, subject, emailAddresses, "", configDtoWithoutNewPassword.convert(configRepository), passwordOverride, configRepository.getLazySecretKey(), mailService); } catch (Exception e) { logger.debug(e.getMessage(), e); return createErrorResponse(e.toString()); } return "{}"; } AdminJsonService(boolean central, boolean offlineViewer, File confDir,
            @Nullable File sharedConfDir, ConfigRepository configRepository, RepoAdmin repoAdmin,
            LiveAggregateRepository liveAggregateRepository, MailService mailService,
            HttpClient httpClient);  }
AdminJsonService { @POST(path = "/backend/admin/send-test-email", permission = "admin:edit:smtp") String sendTestEmail(@BindRequest SmtpConfigDto configDto) throws IOException { SmtpConfigDto configDtoWithoutNewPassword; String passwordOverride; String newPassword = configDto.newPassword(); if (newPassword.isEmpty()) { configDtoWithoutNewPassword = configDto; passwordOverride = null; } else { configDtoWithoutNewPassword = ImmutableSmtpConfigDto.builder() .copyFrom(configDto) .newPassword("") .build(); passwordOverride = newPassword; } String testEmailRecipient = configDtoWithoutNewPassword.testEmailRecipient(); checkNotNull(testEmailRecipient); List<String> emailAddresses = Splitter.on(',').trimResults().splitToList(testEmailRecipient); try { String centralDisplay; String agentDisplay; if (central) { centralDisplay = configRepository.getCentralAdminGeneralConfig().centralDisplayName(); agentDisplay = ""; } else { centralDisplay = ""; agentDisplay = configRepository.getEmbeddedAdminGeneralConfig() .agentDisplayNameOrDefault(); } String subject = "Test email"; AlertingService.sendEmail(centralDisplay, agentDisplay, subject, emailAddresses, "", configDtoWithoutNewPassword.convert(configRepository), passwordOverride, configRepository.getLazySecretKey(), mailService); } catch (Exception e) { logger.debug(e.getMessage(), e); return createErrorResponse(e.toString()); } return "{}"; } AdminJsonService(boolean central, boolean offlineViewer, File confDir,
            @Nullable File sharedConfDir, ConfigRepository configRepository, RepoAdmin repoAdmin,
            LiveAggregateRepository liveAggregateRepository, MailService mailService,
            HttpClient httpClient);   }