Using smtp

smtp(1)

smtp(1) is an SMTP client which can be used to send an email. The message is read from standard input (stdin) until the end-of-file. Unlike sendmail, smtp(1) can authenticate with the mail server and use encryption.

To send an email from localhost (similar to sendmail):

$ smtp -v -F from@example.org to@example.com
From: from@example.org
To: to@example.com
Subject: Alpha Bravo
Message-ID: <randomstring@example.org>
Date: Thu, 24 Jul 2025 11:41:35 -0700
MIME-Version: 1.0 
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Charlie Delta Echo Foxtrot

Replace fromname with the name of the sender and to@example.com with the email to send to.

Press ctrl+d for end-of-file to end the letter.

NOTE: The letter must be RFC-compliant.

If OpenSMTPd is properly configured, smtp should provide the following output:

trying host 127.0.0.1 port 25...
connection ready...
test-669b2a44b7f75@spamscore.net: EOM: 250 2.0.0 a8f7281d Message accepted for delivery
mail done...
connection ready...
connection closed...
done...

It's also possible to put the message inside a file, and to pipe that file to smtp(1):

$ smtp -v -F fromname to@example.com < ~/letter

Authentication

It's possible to connect to an SMTP server remotely. Suppose a user wants to send an email from a home laptop using a remote mailserver.

First, create a file authfile that contains two lines: the username on the first line, and password on the second line:

username
password

If the file letter contains the letter:

From: from@example.org
To: to@example.com
Subject: Alpha Bravo
Message-ID: <randomstring@example.org>
Date: Thu, 24 Jul 2025 11:41:35 -0700
MIME-Version: 1.0 
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Charlie Delta Echo Foxtrot

Then, to send using port 465 (submissions port), issue this command from the laptop:

$ smtp -a authfile -F from@example.org -s smtps://example.org:465 to@example.com < letter

To send using port 587 (submission port), issue this command from the laptop:

$ smtp -a authfile -F from@example.org -s smtp+tls://example.org:587 to@example.com < letter