Sending Mail with netcat

Here's how to send a letter using netcat:

$ nc example.com 25 
220 example.com ESMTP OpenSMTPD

Next, we type HELO followed by our sending domain:

HELO example.com
250 example.com Hello example.com [38.81.163.143], pleased to meet you

Afterwards, we type our sending mail address:

MAIL FROM: <from@example.com>
250 2.0.0 Ok

And the destination mail address:

RCPT TO: <to@example.com>
250 2.1.5 Destination address valid: Recipient ok

Then we type DATA followed by our email:

DATA
354 Enter mail, end with "." on a line by itself
From: from@example.com
To: to@example.com
Subject: Alpha Bravo
Date: Wed, 18 Sep 2024 16:26:35 -0700
MIME-Version: 1.0 
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Charlie Delta Echo Foxtrot

We then type . to end the email, then QUIT:

.
250 2.0.0 e57f9a36 Message accepted for delivery
QUIT
221 2.0.0 Bye

Here's the complete process:

$ nc example.com 25 
220 example.com ESMTP OpenSMTPD
HELO example.com
250 example.com Hello example.com [38.81.163.143], pleased to meet you
MAIL FROM: <from@example.com>
250 2.0.0 Ok
RCPT TO: <to@example.com>
250 2.1.5 Destination address valid: Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
From: from@example.com
To: to@example.com
Subject: Alpha Bravo
Date: Wed, 18 Sep 2024 16:26:35 -0700
MIME-Version: 1.0 
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Charlie Delta Echo Foxtrot
.
250 2.0.0 e57f9a36 Message accepted for delivery
QUIT
221 2.0.0 Bye