use of com.epam.ta.reportportal.util.email.EmailService in project service-api by reportportal.
the class LaunchNotificationSubscriber method handleEvent.
@Override
public void handleEvent(LaunchFinishedEvent launchFinishedEvent, Project project, Launch launch) {
boolean isNotificationsEnabled = BooleanUtils.toBoolean(ProjectUtils.getConfigParameters(project.getProjectAttributes()).get(ProjectAttributeEnum.NOTIFICATIONS_ENABLED.getAttribute()));
if (isNotificationsEnabled) {
Integration emailIntegration = getIntegrationHandler.getEnabledByProjectIdOrGlobalAndIntegrationGroup(project.getId(), IntegrationGroupEnum.NOTIFICATION).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, "EMAIL"));
Optional<EmailService> emailService = mailServiceFactory.getDefaultEmailService(emailIntegration);
emailService.ifPresent(it -> {
launchRepository.refresh(launch);
sendEmail(launch, project, it, launchFinishedEvent.getBaseUrl());
});
}
}
use of com.epam.ta.reportportal.util.email.EmailService in project service-api by reportportal.
the class EmailServerIntegrationService method checkConnection.
@Override
public boolean checkConnection(Integration integration) {
Optional<EmailService> emailService = emailServiceFactory.getEmailService(integration);
if (emailService.isPresent()) {
try {
emailService.get().testConnection();
} catch (MessagingException ex) {
LOGGER.error("Cannot send email to user", ex);
fail().withError(FORBIDDEN_OPERATION, "Email configuration is incorrect. Please, check your configuration. " + ex.getMessage());
}
// if an email integration is new and not saved at db yet - try to send a creation integration message
if (integration.getId() == null) {
try {
EmailSettingsEnum.AUTH_ENABLED.getAttribute(integration.getParams().getParams()).ifPresent(authEnabled -> {
if (BooleanUtils.toBoolean(authEnabled)) {
String sendTo = EmailSettingsEnum.USERNAME.getAttribute(integration.getParams().getParams()).orElseThrow(() -> new ReportPortalException(EMAIL_CONFIGURATION_IS_INCORRECT, "Email server username is not specified."));
emailService.get().sendConnectionTestEmail(sendTo);
}
});
} catch (Exception ex) {
fail().withError(EMAIL_CONFIGURATION_IS_INCORRECT, formattedSupplier("Unable to send connection test email. " + ex.getMessage()));
}
}
} else {
return false;
}
return true;
}
Aggregations