[Linux] 4 methods to send e-mails from the console

1. First method.

We will use the “sendmail” command.

Create a file.

$ vi /tmp/email.txt

It should have this content.

Subject: E-mail testing

E-mail content on the first line.
E-mail content on the second line.

In order to send the e-mail, execute this command.

$ sendmail user@domain.com < /tmp/email.txt

2. Second method.

By using the “mail” command.

Execute this.

$ mail -s E-mail Testing user@domain.com < /dev/null

“-s E-mail testing” is the subject of the mail.

Sending the e-mail with a file that is attached.

$ mail -a /opt/db.sql -s Backup File user@domain.com < /dev/null

-a /opt/db.sql (name of the file that is attached).

Sending the e-mail to multiple persons.

$ mail -s Test Email user1@domain.com,user2@domain.com < /dev/null

3. Third method.

By using the mutt command.

It is very similar to the mail command.

mutt -s Test Email user@domain.com < /dev/null

Mutt with attach.

mutt -s Testing E-mail -a /opt/db.sql user@domain.com < /dev/null

4. Forth method.

Using the telnet command.

$ telnet localhost smtp

Connected to localhost.localdomain (
Escape character is ^].
HELLO gmail.com
250 incvice.com Hello incvice.com []
mail from: admin@incvice.com
250 2.1.0 admin@incvice.com Sender ok
rcpt to: admin@incvice.com
250 2.1.5 admin@incvice.com Recipient ok
354 Enter mail, end with . on a line by itself
250 2.0.0 r9M95xgc014513 Message accepted for delivery
Connection closed by foreign host.