Note: To send email from the terminal, ensure you have a mail server set up and working correctly.

Mail

The first and simplest way to send email from the Linux terminal is to use the mail utility. This simple utility allows you to specify the recipient, email subject and even add attachments with a few options. By default, the mail utility comes preinstalled in most Linux distributions. You can verify whether you have it installed by executing the which command as follows: if you get a result like “/usr/bin/mail”, then it is already installed on your distro. If you don’t have mail installed by default on your Linux distro, you can install it using the package manager for your distro. For example, on Debian, you would run the command: To use mail to send an email, use the mail command followed by the -s option and specify the email subject. For example, to send a message stored in the file “message.txt”, use the command: The above command will read the contents of the file and use it as the message body. You can also pass the message body from a command such as echo. For example: To add attachments to the email, use the -A option. For example:

Sendmail

The next utility you can use to send mail from the terminal is Sendmail, a simple yet powerful utility that can help you send email from the terminal. If you do not have the Sendmail utility installed, you can install it: To use this utility, start by creating a file containing the following as email content: The Sendmail utility will locate the subject header and use it as the subject title for your email. You can pass this by using the command:

Telnet

For those who spend much of their time working with remote servers, telnet is probably the go-to tool to send email. To use it, start by launching the terminal and entering the command: If you have the mail server running on a different port, replace 25 with the target port. Once connected, use telnet to say hello to a server: Note that some servers will also reply to ehlo instead of helo or sometimes either. Next, set the email sender: Set the recipient of the email: Compose the mail with the following format:

Mutt

Mutt is another helpful utility for sending and reading email from the terminal. You may find it similar to the mail command. To install it, run the command: To send an email with mutt, use the command: The above command passes to the mutt utility the content of the sendmail.txt as the email body.

Wrapping Up

It can come in very handy when you’re working within a terminal-only environment to be able to send email from the Linux terminal. Read on to learn how to use the lp command to print files from the Terminal and search the Web from the terminal with S.