Learn how to read and send email directly from the Linux terminal. Whether you’re managing servers, automating reports, or simply prefer working without a graphical interface, the command line offers powerful tools for handling email efficiently.
Using the terminal to manage email is ideal for:
There are several utilities available for sending email via the command line:
mailsendmailmuttssmtpmailxWe’ll use mailx in this example. To install it on Debian-based systems:
sudo apt update
sudo apt install mailutils
echo "Hello! This is a test email from the terminal." | mail -s "Test Subject" recipient@example.com
Explanation:
echo defines the body of the email-s sets the subjectrecipient@example.com is the recipient’s addressecho "Please see the attached file." | mail -s "Attachment Included" -A /path/to/file.pdf recipient@example.com
muttmutt is a powerful text-based email client that supports IMAP, POP3, and SMTP. To install:
sudo apt install mutt
Create or edit your ~/.muttrc file:
set imap_user = "your@email.com"
set imap_pass = "yourpassword"
set folder = "imaps://imap.yourmail.com/"
set spoolfile = "+INBOX"
Then launch the client:
mutt
Command-line email is perfect for automation. For example, to notify yourself when a backup completes:
mail -s "Backup Completed" your@email.com <<< "The backup finished successfully."
cron to schedule regular email reportsManaging email from the Linux command line is a practical skill for anyone working in server environments or automation. With tools like mailx and mutt, you can send, read, and automate email tasks without ever opening a GUI. Try it out and see how much more efficient your workflow can become.