There are multiple commands that allow us to send emails using the command line. The traditional way this has been done, usually to check if a mail server is working properly has been to establish a connection via telnet and send the raw SMTP commands.

telnet
Shell

On the other hand, as we have mentioned, we can use specific command line commands and programs that serve this purpose.

ssmtp

In this case we use a text file containing the raw SMTP commands that we already use with telnet, and also the content of the mail itself.

ssmtp "<recipient@mail.com>" < mail.txt
Shell

sendmail

echo "Email test" | sendmail "<recipient@mail.com>"
Shell

And if we use the text file from the previous example

echo "Email test" | sendmail -v "<recipient@mail.com>" < mail.txt
Shell

curl

curl --url "smtps://smtp.gmail.com:465" --ssl-reqd --mail-from "<sender@mail.com>" --mail-rcpt "<recipient@mail.com>" --upload-file mail.txt --user "<usuariogmail:contraseñagmail>"
Shell

swaks

swaks --header "Email test" --to "<recipient@mail.com>" -s smtp.gmail.com:587 -tls -au "<usuariogmail>" -ap "<contraseñagmail>"
Shell
swaks --header "Email test" --to "<recipient@mail.com>" -s smtp.gmail.com:587 -tls -au "<usuariogmail>" -ap "<contraseñagmail>" --attach -d ./mail.txt
Shell

mutt

mutt -s "Email test" "<recipient@mail.com>" < /dev/null
Shell
mutt -s "Email test" "<recipient@mail.com>" -a mail.txt < /dev/null
Shell
mutt -s "Email test" "<recipient@mail.com>" -a mail.txt < email.html
Shell

mailx

mailx -s "Email test" < /dev/null "<recipient@mail.com>"
Shell
echo "Cuerpo del correo" | mailx -s "Email test" "<recipient@mail.com>"
Shell

mail

mail -a "Content-Type: text/html" -s "Email test" < email.html "<recipient@mail.com>,<recipient2@mail.com>"
Shell

openssl

openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof
EHLO localhost
AUTH PLAIN "passwordhash"
MAIL FROM: <sender@mail.com>
RCPT TO: <recipient@mail.com>
DATA

Subject: Email test

Cuerpo de correo
.
Shell

A mail.txt file can have the following content:

From: sender@mail.com
To: recipient@mail.com
Subject: Email test
Content-Type: text/html; charset="utf8"


<html>
<body>
<div style="
	background-color:
	#abcdef; width: 300px;
	height: 300px;
	">
</div>
Here you can add mail content.
</body>
</html>
Text

Of course these are only examples and the parameters must be adapted to individual needs.