Ubuntu 18.04: Error with mailx smtp – mailx: unrecognized option "-S'"?

I was trying to send an email to multiple persons using mailx (mailx (GNU Mailutils) 3.4). I did that successfully on a previous version of Ubuntu, v16.04, and the script was working fine. Now I have Ubuntu 18.04 and the following problem:

mailx: unrecognized option -S
mailx: unrecognized option -S
mailx: unrecognized option -S

what should I do?

My script is as follow:

while IFS=";" read name mailAdress
     printf "Dear $name, \n\n something something... "  | mailx -s "Title" -S smtp=smtps://mySMPTadress -S smtp-auth=login -S smtp-auth-user="MyUserName" -S smtp-auth-password='MyPassword' -S from="MyName <MyEmailAdress>"  mailAdress
done < "$FILE"

file speakers.csv looks like this

Klaus A;[email protected]*****.de
Alessandra B;[email protected]****.it
Serge C;[email protected]****.fr

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Debian and Ubuntu have replaced Heirloom mailx with s-nail mailx. Both support that option. But there are several other mailx commands from other packages which do not, including the GNU Mailutils mailx which you have apparently unknowingly switched to.

On the gripping hand, as Fabby said, do not pass user credentials around in command arguments (or environment variables).

Further reading

  • mailx. Ubuntu 16.04 manual pages.
  • mailx. Ubuntu 16.04 manual pages.
  • mailx. Ubuntu 16.04 manual pages.
  • mailx. Ubuntu 14.04 manual pages.
  • s-nail. User commands. s-nail. Debian manual pages.
  • mailx. User commands. GNU mail utils. Debian manual pages.
  • mailx. General Commands Manual. BSD mailx. Debian manual pages.
  • mailx. User commands. NMH. Debian manual pages.
  • Difference between mail and mailx?

Solution 2

Quick and dirty:

mailx is a link to s-nail so you should use s-nail instead as according to its Bionic man page it still has the -S option.

Do it properly:

You should avoid sending mail like that because anyone that has access to ps can read your password as it’s on the command line and you should look into using the -A (account) option to store this in the .netrc file that only the user and root have access to. (Read the full man page)

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply