Home-Software Development-Send and Read Email via the Linux Command Line
Linux Command Line

Send and Read Email via the Linux Command Line

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.

Why Use the Command Line for Email?

Using the terminal to manage email is ideal for:

  • System administrators working on headless servers
  • Developers automating notifications
  • Power users who prefer minimal interfaces
  • Anyone scripting tasks that involve email

Sending Email from the Terminal

Installing Required Tools

There are several utilities available for sending email via the command line:

  • mail
  • sendmail
  • mutt
  • ssmtp
  • mailx

We’ll use mailx in this example. To install it on Debian-based systems:

sudo apt update
sudo apt install mailutils

Sending a Simple Email

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 subject
  • recipient@example.com is the recipient’s address

Sending an Email with an Attachment

echo "Please see the attached file." | mail -s "Attachment Included" -A /path/to/file.pdf recipient@example.com

Reading Email from the Terminal

Using mutt

mutt is a powerful text-based email client that supports IMAP, POP3, and SMTP. To install:

sudo apt install mutt

Basic Configuration Example

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

Automating Email with Scripts

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."

Tips and Best Practices

  • Use cron to schedule regular email reports
  • Encrypt sensitive messages using GPG
  • Test email scripts locally before deploying to production

Conclusion

Managing 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.

logo softsculptor bw

Experts in development, customization, release and production support of mobile and desktop applications and games. Offering a well-balanced blend of technology skills, domain knowledge, hands-on experience, effective methodology, and passion for IT.

Search

© All rights reserved 2012-2026.