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

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

sendmail

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

And if we use the text file from the previous example

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

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>"

swaks

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

mutt

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

mailx

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

mail

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

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
.

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>

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