@Test public void shouldSendTestEmailWithSTARTTLS() { smtpServer.getServer().setEnableTLS(true); smtpServer.getServer().setRequireTLS(true); configure(); when(configuration.getSecureConnection()).thenReturn("STARTTLS"); try { underTest.sendTestEmail("user@nowhere", "Test Message from SonarQube", "This is a test message from SonarQube."); fail("An SSL exception was expected a a proof that STARTTLS is enabled"); } catch (EmailException e) { // We don't have a SSL certificate so we are expecting a SSL error assertThat(e.getCause().getMessage()).isEqualTo("Could not convert socket to TLS"); } }
sent = true; } catch (EmailException e) { Throwable cause = e.getCause(); if(cause instanceof ParseException || cause instanceof IllegalWriteException || markFailed(id, cause); } else if(cause instanceof MessagingException) { if(e.getCause() instanceof SendFailedException && e.getCause().getCause() instanceof SMTPAddressFailedException) { logger.warn("Mail not sent due to known server error, marking as failed"); markFailed(id, e);
if (e.getCause() instanceof AuthenticationFailedException) { CmsMailHost host = OpenCms.getSystemInfo().getMailSettings().getDefaultMailHost();
if (e.getCause() instanceof AuthenticationFailedException) { CmsMailHost host = OpenCms.getSystemInfo().getMailSettings().getDefaultMailHost();
@Test public void testSendBadHostName() { try { getMailServer(); email = new MockEmailConcrete(); email.setSubject("Test Email #1 Subject"); email.setHostName("bad.host.com"); email.setFrom("me@home.com"); email.addTo("me@home.com"); email.addCc("me@home.com"); email.addBcc("me@home.com"); email.addReplyTo("me@home.com"); email.setContent( "test string object", " ; charset=" + EmailConstants.US_ASCII); email.send(); fail("Should have thrown an exception"); } catch (final EmailException e) { assertTrue(e.getCause() instanceof ParseException); fakeMailServer.stop(); } }