Linux: Specify Mail Client’s SMTP server

As far as I know, almost all Linux distro’s have a built in mail client, known as sendmail. They also often have full mail server capability.

The other day, I had an issue with an application that had the ability to send email. In the application’s GUI, one could configure SMTP settings, but it wouldn’t accept the settings. All test indicated the SMTP settings were correct. To confirm that it was the application and not the server or mail server at fault, I wanted to send an email, using the CLI of the application server (machine A) through a fully configured instance of Postfix running on server B. I also knew server B was working correctly as I could use PowerShell’s Send-MailMessage cmdlet from my workstation:

Basically, I wanted to send mail from Server A’s mail client in a similar fashion to the PowerShell cmdlet. My issue was how to tell it what SMTP server to use. In the end, it was very easy. All I had to do was add an environment variable:

In my case:

To remove:

To send a test mail:

Reference: http://stackoverflow.com/a/12844182/3167379

It turned out that the fault was indeed with the application server and a quick restart of the Tomcat service allowed the application to accept the SMTP settings! I hate JAVA!!!

Please feel free to leave a comment...