Linux 4 methods to send emails from the console, command line?

Linux 4 methods to send emails from the console, command line?

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

Trying 127.0.0.1
Connected to localhost.localdomain (127.0.0.1).
Escape character is ^].
HELLO gmail.com
250 incvice.com Hello incvice.com [127.0.0.1]
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
data
354 Enter mail, end with . on a line by itself
Testing
.
250 2.0.0 r9M95xgc014513 Message accepted for delivery
quit
Connection closed by foreign host.

Add a comment: