Mail system

There are three main functions that make up an e-mail system.

  • First there is the Mail User Agent (MUA) which is the program a user actually uses to compose and read mails.
  • Then there is the Mail Transfer Agent (MTA) that takes care of transferring messages from one computer to another.
  • And last there is the Mail Delivery Agent (MDA) that takes care of delivering incoming mail to the user's inbox.
Function Name Tool which do this
Compose and read MUA (User Agent) mutt, thunderbird
Transferring MTA (Transfer Agent) msmtp, exim4, thunderbird
Delivering incoming mail to user's inbox MDA (Devliery agent) exim4, thunderbird


It exists two types of MTA (Mail Transfert Agent)

  • Mail server : like postfix, or sendmail-server
  • SMTP client, which only forward to a SMTP relay : like ssmtp (deprecated since 2013), use mstmp instead,

Check what is your email sender, by looking at the sym link of sendmail

which sendmail

ls -l /usr/sbin/sendmail
lrwxrwxrwx 1 root root 5 Jul 15  2014 /usr/sbin/sendmail -> ssmtp

In this case, ssmtp in my mail sender


MSMTP (client config)

msmtp est un client SMTP très simple et facile à configurer pour l'envoi de courriels.
Son mode de fonctionnement par défaut consiste à transférer les courriels au serveur SMTP que vous aurez indiqué dans sa configuration. Ce dernier se chargera de distribuer les courriels à leurs destinataires.
Compatible :

  • sendmail ou bsd-mailx
  • Handle TLS
  • Multiples account
  • Multiple authentication method
  • Distribution distribution


apt install msmtp msmtp-mta
vim /home/baptiste/.msmtprc
hashtag Valeurs par défaut pour tous les comptes.
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        ~/.msmtp.log

hashtag Exemple pour un compte Gmail
account        gmail
port           587
user           username
password       plain-text-password

hashtag Définir le compte par défaut
account default : gmail

Send an email

Using bsd-mailx (prefered)

First, ensure you have your client (msmtp) configured /home/baptiste/.msmtprc
Get the binary mail

apt install bsd-mailx
echo "mon message ici" | mail -s "un super sujet ici"

Using sendmail

Test email sending

echo "mon message ici" | sendmail

You run the command... and, oops: sendmail: Cannot open mailhub:25. The reason for this is that we didn't provide mailhub settings at all. In order to forward messages, you need an SMTP server configured. That's where SSMTP performs really well: you just need to edit its configuration file once, and you are good to go.

Using NetCat (hardcore method)

Manually write each steps of the SMTP protocol.

nc 25
telnet 25
Connected to
Escape character is '^]'.
220 ESMTP Postfix
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
Subject: test message
This is the body of the message!
250 2.0.0 Ok: queued as 2D8FD4C80FF
221 2.0.0 Bye
Connection closed by foreign host.

results matching ""

    No results matching ""

    results matching ""

      No results matching ""