You could try connecting to the remote admin port (which I believe is port 4555 by default):
boolean jamesIsRunning = new Socket().with {
try {
connect( new InetSocketAddress( 'localhost', 4555 ), 100 )
close()
true
}
catch( e ) {
false
}
}
Or if the remote admin port isn't open on your installation, you could try the SMTP port