public void startServer(int port, InetAddress bindAddress) throws BindPortException, OutOfRangePortException {
LOGGER.debug("Starting server on port {}", port);
try {
smtpServer.setBindAddress(bindAddress);
smtpServer.setPort(port);
smtpServer.start();
} catch (RuntimeException exception) {
if (exception.getMessage().contains("BindException")) {
LOGGER.error("{}. Port {}", exception.getMessage(), port);
throw new BindPortException(exception, port);
} else if (exception.getMessage().contains("out of range")) {
LOGGER.error("Port {} out of range.", port);
throw new OutOfRangePortException(exception, port);
} else {
LOGGER.error("", exception);
throw exception;
}
}
}