Sibidharan Sibidharan - 1 year ago 111
Linux Question

Find sendmail version (sSMTP or Postfix or other)

I have a script which runs on multiple servers. Some servers are using sSMTP and some are using postfix.

I want to find which version of sendmail my server is running in runtime, because

is not supported in sSMTP but is mandatory in Postfix

Now the challenge begins.

sendmail -V
on sSMTP varient outputs
sSMTP 2.64 (Not sendmail at all)

the postfix variant doesn't have the
option for displaying the version.

I managed to accomplish it with the following snippet.

VER=$(sendmail -V 2>/dev/null)
if [[ "sSMTP" == $VER* ]]; then
echo $BODY | sendmail $EMAIL #sSMTP
echo $BODY | sendmail -t $EMAIL #postfix

Is there a more efficient method to achieve this?

I want to find what varient of sendmail is in my server. Not just postfix or sSMTP.

Answer Source

How about this?

type -p sendmail |
xargs dpkg -S

Some packages put it in /usr/lib, others in /usr/sbin, etc. This obviously requires them to be on your PATH.

dpkg -S tells you the name of the package which installed a file, and type -p is used to find sendmail on your PATH so we can pass that to dpkg -S. This obviously requires a Debian-based distro (Ubuntu, Mint, what have you).

On an ssmpt system, with /usr/lib on the PATH, the output is

ssmtp: /usr/lib/sendmail

On a Postfix system with a slightly different PATH,

postfix: /usr/sbin/sendmail

I don't think I have an Exim or Qmail system where I can try this, but they should be predictably similar.

As an aside, if you want to pass a multi-line string such as an email message to sendmail by way of a pipe from echo, you will need to quote the multi-line variable in order for it to work.

echo "$body" | sendmail -t

If you want to use sendmail -t, the "$body" should contain the To: header for sendmail to parse -- this is what the -t option does, so I don't think you want a variable with a recipient address in this scenario.

Also, don't use uppercase for your private variable names; uppercase variable names are reserved for system use.

Finally, as already commented elsewhere, I believe both SSMTP and Postfix support sendmail -t, as does practically every other Sendmail implementation I have seen. So in the end, I don't think you actually need this code to achieve that goal.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download