I have multiple Ubuntu servers with Java applications running on it. One of the application's functions is to sent an email. Now we using exim4 as the MTA.

I would like to replace exim with something lighter. My first idea was msmtp or ssmtp. Mail from command line gone well, but then I found the problem:

Java application trying to sent an email on localhost:25 and getting the following exception:

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25
    Caused by: java.net.ConnectException: Connection refused

and it is correct behavior since msmtp/ssmtp does not listen on localhost:25. I am not able to change the Java code, so I need to pick up an email on localhost:25 on server and then put it to central mailserver through SMTP. Is there any way to run msmtp/ssmtp as a daemon listening on localhost:25 ? Or maybe forward localhost:25 to msmtp/ssmtp's STDIN somehow?

  • I think nullmailer fits the bill. – Gilles Dec 4 '14 at 1:21
  • @Gilles nullmailer doesn't listen on port 25, it merely provides an implementation of sendmail. – Andrew Ferrier Mar 19 '16 at 13:12

The links below provides all the MTA choices you can choose, according to your Ubuntu version:

MTA - Ubuntu 12.04

MTA - Ubuntu 14.04

You can also check the Archwiki page on Setting up ssmtp to use port 25.

SSMTP and MSMTP still are not full fledged MTA's. This unix.se provides details for a comprehensive lists of MTA's available and they as well are already packaged for ubuntu.


I've managed to change Java code from localhost to mailserver address

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.