Sending Emails From Terminal In Linux

You can send emails from the terminal in Linux by using the command line tool called mail. This tool is typically pre-installed on most Linux distributions. To send an email, you would use the syntax

echo "message body" | mail -s "subject" recipient@email.com

You can also include attachments by using the -a option and specifying the path to the file you want to attach.

echo "message body" | mail -s "subject" -a /path/to/attachment recipient@email.com

You can also use other command line mail clients such as mutt, mailx, and msmtp.

Architecture of an Email System

An email system consists of several different components that work together to send and receive messages. The main components of an email system are

Email System Architecture MUA (Mail User Agent) MTA (Mail Transfer Agent) MDA (Mail Delivery Agent) SMTP POP3/IMAP DNS Mailbox

  • Mail User Agent (MUA) This is the software that users interact with to compose, send, and receive email. Examples include Microsoft Outlook, Apple Mail, and Thunderbird.

  • Mail Transfer Agent (MTA) The MTA is responsible for transmitting email messages from one server to another. Examples of MTAs include Postfix, Exim, and Sendmail.

  • Mail Delivery Agent (MDA) The MDA receives messages from the MTA and delivers them to the appropriate mailbox on the local server.

  • Mailbox This is where email messages are stored on the server. There are several types of mailboxes including Maildir, mbox and IMAP.

  • Simple Mail Transfer Protocol (SMTP) This is the protocol used for sending email messages between servers.

  • Post Office Protocol (POP) and Internet Message Access Protocol (IMAP) These are the protocols used for retrieving email messages from a server.

  • DNS The Domain Name System is used to resolve domain names to IP addresses, which is necessary for routing email messages.

msmtp

msmtp is a command line mail transfer agent (MTA) for sending email. It allows users to send email through an SMTP (Simple Mail Transfer Protocol) server from the command line, rather than using a traditional email client like Microsoft Outlook or Apple Mail.

msmtp is designed to be lightweight and easy to use, and can be used as a replacement for the built-in sendmail command on Linux and Unix systems. It is often used in conjunction with other command-line tools like Mutt and OfflineIMAP for a simple and efficient email workflow.

One of the main features of msmtp is its ability to handle multiple SMTP accounts and configure them through a configuration file. This allows users to switch between different accounts easily when sending email.

msmtp also supports various security features such as SSL/TLS encryption, SMTP-AUTH, and STARTTLS. It also allows you to specify a different certificate for each SMTP server you connect to.

To use msmtp, you need to configure it with the necessary SMTP server and account information and then use the msmtp command to send email.

echo "message body" | msmtp -a default -t recipient@example.com

Please note that msmtp does not receive emails, it only sends emails via SMTP server.

mutt

Mutt is a command-line based email client for Unix-like systems. It is designed to be small and easy to use, and can be used as a replacement for other email clients like Microsoft Outlook or Apple Mail.

Mutt supports various features such as reading and sending email, handling multiple mailboxes, and supporting various mailbox formats. It also supports a wide range of protocols for sending and retrieving email, including SMTP, IMAP, and POP3.

One of the main advantages of Mutt is its powerful keyboard shortcuts and command language, which allows users to quickly navigate and manage their email. It also supports various customization options through its configuration file, allowing users to tailor the program to their specific needs.

Mutt also supports various security features such as SSL/TLS encryption, PGP/GPG encryption, and S/MIME.

To use Mutt, you need to configure it with the necessary account information and then use the mutt command to open the email client in the terminal.

mutt

You can also compose and send an email directly from the command line

mutt -s "subject" recipient@example.com < message.txt

Mutt can also be used in conjunction with other command-line tools, such as msmtp for sending email, and OfflineIMAP for retrieving email from remote servers.

Comparison of Email Tools

Tool Primary Function Configuration Features
mail Send emails Simple Basic sending, attachments
msmtp SMTP client Config file Multiple accounts, SSL/TLS
mutt Full email client Extensive Read/send, encryption, multiple protocols

Conclusion

There are several command line tools available for sending and managing email on Linux systems, such as mail, msmtp, and mutt. Each tool has its own unique features and capabilities mail is simple for basic sending, msmtp excels at SMTP configuration with multiple accounts, and mutt provides a full-featured email client experience. The choice depends on your specific needs and workflow preferences.

Updated on: 2026-03-17T09:01:38+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements