Three ways to send email from an Ubuntu command line

If you know the real power of the command line, you will not want to leave the Terminal and go somewhere else to perform any of your daily technical tasks. There is always a way to do almost all of our things right in the Terminal. So why sending emails should be different! Using the Terminal makes certain tasks more efficient and even faster. The command line tools do not consume too many resources and, thus, form excellent alternatives to widely used graphical applications, especially if you are stuck on old hardware. Sending emails from the Terminal becomes especially convenient when you can write shell scripts to send emails and automate the entire process.

In this article, we describe three ways to send email at the Ubuntu command line (from a configured email id).

  • ssmtp team
  • sendmail command
  • fool team

We ran the commands and procedures mentioned in this article on the Ubuntu 18.04 LTS system.

Open the Terminal application either through the search bar of the application launcher, or using the keyboard shortcut Ctrl + Alt + T, and then use one of the following methods to send e-mail.

Method 1: send an email using the ssmtp command

SSMTP sendmail emulator is only for sending for machines that usually receive mail from a centralized mail hub (via pop, imap, nfs mounts or other methods). It provides the functionality people and programs need to send mail through standard user agents or / usr / bin / mail. If this utility is not installed on your system, run the following command to install it:

$ sudo apt- get update

And then,

$ sudo apt-get install ssmtp

The following command can be used to create and send an email:

$ ssmtp [email protected]

Press Enter, and then enter the subject in the following format:

Subject: sample subject comes here

When you press Enter, you will be allowed to enter the body of the letter. When you finish typing the message body, press Ctrl + D. This will mark the end of the message body and send it to the corresponding recipient ID.

Method 2: use the sendmail command

Sendmail is a universal email routing system that supports various methods of sending and delivering mail, including the SMTP protocol used to send email over the Internet. Sendmail, which is the smtp server, requires smtp to be installed on your system. Then you can use it as follows. Create a text file in the following format:

Subject: Email subject comes here
Email Body Line 1
Email Body line 2

Save the file, and then you can use the file name in the following command:

$ sendmail [email protected] < filename.txt

Method 3: using the mutt command

Mutt is a small but very powerful text-based program for reading and sending emails on UNIX operating systems, including support for color terminals, MIME, OpenPGP, and multi-threaded sorting.

This is the syntax that you will use to send an email without attachment:

$ mutt -s "Subject comes here" [email protected] < /dev/null

If you want to attach the file to your email, use the following format to indicate the location of this attachment:

$ mutt -s "Subject comes here" -a /path/to/file [email protected] < /dev/null

Your letter will be sent to the specified recipient.

There is a similar command called mail, which is pretty much used just like mutt to send emails from the command line.

You can also use telnet to send emails from the Terminal. Although Linux administrators typically use it to connect to remote ports and servers, we’ll talk about how you can use it to send emails in another article. Before that, you can try the above methods and see what works for you.

Three ways to send email from an Ubuntu command line