SonarSource/sonarqube · error · SonarException

Unknown type of SMTP secure connection:

Error message

Unknown type of SMTP secure connection: 

What it means

EmailNotificationChannel.configureSecureConnection maps the sonar.email.secureConnection setting to JavaMail configuration, accepting only SSL, STARTTLS, or NONE. Any other value throws SonarException naming the unknown value.

Solutions

  1. Set sonar.email.secureConnection to exactly SSL, STARTTLS, or NONE.
  2. If the server needs plain TLS-on-connect, use SSL; for explicit upgrade use STARTTLS.
  3. Restart/re-test the SMTP configuration via the 'Send test email' button after changing the value.

Example fix

// before
sonar.email.secureConnection=TLS
// after
sonar.email.secureConnection=STARTTLS
Defensive patterns

Strategy: validation

Validate before calling

java.util.Set<String> allowed = java.util.Set.of("SSL", "STARTTLS", "NONE");
if (!allowed.contains(secureConnection.toUpperCase(java.util.Locale.ROOT))) throw new IllegalArgumentException("sonar.email.secureConnection must be SSL, STARTTLS or NONE");

Try / catch

try { mailService.sendTestEmail(); } catch (SonarException e) { if (e.getMessage().startsWith("Unknown type of SMTP secure connection")) { log.error("Fix sonar.email.secureConnection value"); } throw e; }

Prevention

When it happens

Trigger: sonar.email.secureConnection set to anything other than 'SSL', 'STARTTLS', or 'NONE' (case-insensitive), e.g. 'TLS', 'ssl/tls', blank string with different meaning.

Common situations: Admin entering 'TLS' expecting STARTTLS; documentation from other products ('ssl_on'); typos; values migrated from older SonarQube versions.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/73525f5f85706bb4. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java:358

  private void configureSecureConnection(Email email) {
    if (CI.equals(configuration.getSecureConnection(), "SSLTLS")) {
      email.setSSLOnConnect(true);
      email.setSSLCheckServerIdentity(true);
      email.setSslSmtpPort(String.valueOf(configuration.getSmtpPort()));

      // this port is not used except in EmailException message, that's why it's set with the same value than SSL port.
      // It prevents from getting bad message.
      email.setSmtpPort(configuration.getSmtpPort());
    } else if (CI.equals(configuration.getSecureConnection(), "STARTTLS")) {
      email.setStartTLSEnabled(true);
      email.setStartTLSRequired(true);
      email.setSSLCheckServerIdentity(true);
      email.setSmtpPort(configuration.getSmtpPort());
    } else if (CI.equals(configuration.getSecureConnection(), "NONE")) {
      email.setSmtpPort(configuration.getSmtpPort());
    } else {
      throw new SonarException("Unknown type of SMTP secure connection: " + configuration.getSecureConnection());
    }
  }

  /**
   * Send test email.
   *
   * @throws EmailException when unable to send
   */
  public void sendTestEmail(String toAddress, String subject, String message) throws EmailException {
    try {
      EmailMessage emailMessage = new EmailMessage();
      emailMessage.setTo(toAddress);
      emailMessage.setSubject(subject);
      emailMessage.setPlainTextMessage(message + getServerBaseUrlFooter());
      send(emailMessage);
    } catch (EmailException e) {
      LOG.debug("Fail to send test email to {}: {}", toAddress, e);
      throw e;

View on GitHub (pinned to 184c821202)