Search in sources :

Example 1 with EmailService

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());
        });
    }
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) EmailService(com.epam.ta.reportportal.util.email.EmailService)

Example 2 with EmailService

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;
}
Also used : MessagingException(javax.mail.MessagingException) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) EmailService(com.epam.ta.reportportal.util.email.EmailService) MessagingException(javax.mail.MessagingException) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Aggregations

ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 EmailService (com.epam.ta.reportportal.util.email.EmailService)2 Integration (com.epam.ta.reportportal.entity.integration.Integration)1 MessagingException (javax.mail.MessagingException)1