Sending Mail with netcat

nc(1), or netcat, is a powerful utility for network troubleshooting. It comes as part of the OpenBSD base system.

To send a letter to the mail server example.com on port 25 using nc(1):

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

Next, type HELO followed by the sender's domain. In this example, the sender's domain is example.org:

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

Afterwards, type the sender's mail address:

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

Then type the destination mail address:

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

Then type DATA followed by the email:

DATA
354 Enter mail, end with "." on a line by itself
From: from@example.org
To: to@example.com
Subject: Alpha Bravo
Message-ID: <randomstring@example.org>
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

For each email, the Message-ID must be a unique, randomly generated alphanumeric string.

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.org
250 example.com Hello example.org [198.51.100.2], pleased to meet you
MAIL FROM: <from@example.org>
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.org
To: to@example.com
Subject: Alpha Bravo
Message-ID: <randomstring@example.org>
Date: Sun, 27 Jul 2025 06: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