Sending an email is something you often don’t have to think twice about. Simply fire up your email client, be it web or desktop-based, compose a message, enter the receipent’s email address and click “Send”. What if there is a need for you to send email from the command line, say to report the progress (or failure) of a backup process?
In Linux, sending emails from the terminal is really a piece of cake. You will need to setup a mail server though (Postfix or Sendmail). To make it easier, you can just install “
mailutils” which will then install Postfix for you and allow you to send email using the “
In Ubuntu (or Debian-based) distro, install
mailutils with the command:
It will then prompt you to configure Postfix (if it is not already installed).
And the last thing to configure is the FQDN, which will then be used as the domain name in the “From” field.
Once you have installed “
mailutils“, you can start to send email from the terminal using the following syntax:
For example, to send an email to "firstname.lastname@example.org" with the subject "Send email from terminal", the command to use is:
And this is what you will see in your email inbox:
Mutt is yet another text-based mail client that you can use to send emails from the Terminal. What makes it better than "
- color support
- message threading
- MIME support (including RFC2047 support for encoded headers)
- PGP/MIME (RFC2015)
- POP3 and IMAP support
To install mutt, simply use the command:
To get started, run mutt in the terminal:
This will load your email "inbox".
Press "m" to compose a new email. It will prompt you to enter the recipent's email address.
Next, it will prompt you to enter the Subject.
After that, it will open up a nano text editor where you can compose your message. Click "Ctrl + o" to save and "Ctrl + x" to exit.
Lastly, type "y" to send the email. You should see a "Mail sent" message.
Optionally, you can also attach a file to your email with the "a" keyboard shortcut, or type "c" to add a CC field.
To quit mutt, type "q".
In addition to the "GUI" you see above, mutt can also be used in Bash script via the command line. To send an email using the mutt command:
Did you notice that how similar it is to the "
Mutt works with a config file that you can use to pre-configure your mailbox's detail. You can make use of muttrc builder to quickly generate a ".muttrc" file and save it to your Home folder.
Sending email from terminal is not a difficult task, and in some situations, it is a necessity. The good thing is that Linux comes with useful tool that you can use to send email from the terminal. We have covered mail and mutt, but they are not the only programs available. There are still several other applications that you can use to send email from terminal. Let us know which one is your preferred choice.
Image Credit: Tim Morgan