Send Email in Linux from Command Line

Published on March 13, 2024

Email is one of the primary ways of connecting with people, especially when you want to send attachments or other official messages. One benefit of using Linux is that you can send emails from the command line. Besides, there are different tools you can use, and which to use is a matter of preference.

This post shares different ways of sending emails from the command line in Linux. We will discuss each option, how to install it, and give an example of utilizing it to send an email from command line.

Four Ways of Sending Emails in Linux from Command Line

Using the terminal to send emails in Linux is a quick way of simplifying the process compared to using the graphical options. With this option, you can easily automate the process of sending emails.

Here are the four commonly used options for sending emails in Linux from the command line.

1. Using the “mailutils” Package

First on our list is the “mailutils” package. The package offers the mail command, which allows you to quickly send emails, including attachments, to your recipient’s email address.

To utilize this option, install the “mailutils” package using the command below.

Copy

The “mailutils” package comes with a graphical interface to help with the setup process before you can start sending emails. Click ‘ ok ‘ in the first installation wizard to confirm the details.

You will be prompted to select the mail configuration type on the next screen. Select the default option (Internet Site) and press the OK button.

Continue with the prompts and add the system mail name, the qualified domain name, associated with your machine. Once the installation is completed, you can send emails from the command line.

Use the below syntax to send your first email from the command line.

Copy

We’ve sent our email as shown below. You can add the Cc option or press the enter key to skip it. Next, type the email’s body/message and press the enter key. We added “Greetings!” as our email body/message. Lastly, press the Ctrl + D to send the email.

Still, you can include a file as an attachment using the -A option. Follow the syntax below.

Copy

Here’s an example where we’ve added the ‘names.txt’ as an attachment when sending our email from the terminal.

2. Using the “sendmail” Command

The sendmail command utilizes the SMTP server to send emails to recipients. Although it is supported by different Linux distros, it doesn’t come preinstalled, and you must run the command below to install it.

Copy

Once the installation is complete, you can send an email with an attachment using the syntax below.

Copy

Depending on your goal, you can work around sendmail and have different ways of sending your email.

3. Using the “mpack” Command

Third on our list is the mpack command. It takes a file and encodes it into a MIME message before sending it to the specified recipient. In our case, we will use it to send an email with an attachment to one recipient.

Start by running the command below to install mpack.

Copy

Ensure the process runs smoothly and confirm any prompts that appear.

Copy

We’ve sent our email as shown below.

4. Using the “mutt” Command

Mutt is another email client Linux command that lets you send emails from the terminal, including attachments. Let’s first install it using the command below.

Copy

Once it installs, you can start sending your emails. For our example, we’ve utilized the echo command to add the body of our email. Next, we’ve used the -a option to include a file as an attachment. The -s option allows adding the email’s body. Lastly, we’ve added our recipient client and pressed the enter key to send the email.

Feel free to check the help page for any of the mentioned options for sending emails and learn about the different approaches you can take to customize them.

Conclusion

Linux supports sending emails from the terminal line, provided you know what commands or tools to use. This post has focused on the four commonly used commands for sending emails in Linux from the command line. Hopefully, this post has given you the required knowledge to send emails successfully from the command line in Linux.

New to LinuxMeta? Get Started Now! 

Instantly Deploy Linux & Windows KVM VPS at a Cheap Price