### Question:
MailUtil { public static void sendMessage( Properties props, String to, String subject, String content) throws AddressException, MessagingException { Session session = getMailSession( props ); getSenderEmailAddress(session, props); try { MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(c_fromAddress)); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); msg.setSubject(subject, "UTF-8"); msg.setText(content, "UTF-8"); msg.setSentDate(new Date()); Transport.send(msg); if (log.isInfoEnabled()) { log.info("Sent e-mail to=" + to + ", subject=\"" + subject + "\", used " + (c_useJndi ? "JNDI" : "standalone") + " mail session."); } } catch (MessagingException e) { log.error(e); throw e; } } private  MailUtil(); static void sendMessage( Properties props, String to, String subject, String content);  }### Answer:
@Test public void testSendMail() { String user = System.getProperty( "user.name" ) + "@localhost"; try { MailUtil.sendMessage( m_props, user, "Mail test", "This is a test mail generated by MailUtilTest." ); } catch( MessagingException e ) { if( e.getCause() instanceof ConnectException ) { System.out.println("I could not test whether mail sending works, since I could not connect to your SMTP server."); System.out.println("Reason: "+e.getMessage()); return; } if( e.getCause() instanceof SSLHandshakeException ) { System.out.println("I could not test whether mail sending works, since I don't have the required cert in my keystore."); System.out.println("Reason: "+e.getMessage()); return; } if( e.getCause() == null ) { System.out.println("Reason: "+e.getMessage()); System.out.println("I could not test whether mail sending works, we let the test pass anyway."); return; } e.printStackTrace(); Assertions.fail( "Unknown problem, cause=" + e.getCause() + " (check the console for error report)" ); } catch (Exception e) { e.printStackTrace(); Assertions.fail( "Could not send mail: " + e.getMessage() ); } }