9 mail/mailx Command Examples to Send Emails from Command Line on Linux

20173

Send mails from command line
The mail command is an essential one that should be available on any linux server so that various services and other web applications can generate and transmit emails.
In a previous post we saw how the mail command can be used to send emails from the command line on your linux server.
In this tutorial we shall be using an enhanced version of the mail command. Its called mailx (or just mail when installed), and it can do many more things than what the older mail command from gnu mailutils package can do.
How does it work
The mail/mailx command needs a local smtp server (MTA) running in order to deliver the emails. THe route taken by the email is somewhat like this –
mail -> sendmail -> local MTA -> recipient MTA
The recipient MTA would be gmail’s smtp server if your recipient is someone at gmail.com for instance. For the local MTA, you need to install an smtp server like Postfix. A basic installation of Postfix with minimal configuration would work in most cases.
Install the mailx command
On Ubuntu/Debian based systems the mailx command is available from 2 different packages –
1. heirloom-mailx
2. bsd-mailx
We shall be using the heirloom-mailx package because…

Read full post here
9 mail/mailx command examples to send emails from command line on Linux

Read more at Binary Tides