Join us

How to Send Emails with Telnet on Windows and Linux

Send-emails-with-Telnet-featured-image-700x363.png

Simple steps will help you to launch send email using Telnet option

Telnet or Teletype Network Protocol is a client/server application protocol. It allows users to connect with the email servers directly from the command line of their computer. 

The primary purpose of Telnet is to establish a standardized connection between terminal-oriented devices and processes (RFC 854). However, it’s also widely used for sending emails and, in that process, testing the Simple Mail Transfer Protocol (SMTP) connection. 

Today we’ll explain how to send emails using Telnet on Windows and Linux operating systems. 

Send emails via Telnet on Windows 

Prerequisites 

  • Administrator access or equivalent
  • Configured SMTP server 
  • Telnet enabled on the host’s computer or machine 
  • Basic knowledge of PowerShell and command prompt commands 

Installing the Telnet client 

Most versions of Windows operating systems don’t have Telnet enabled by default. So, to get started, first, we need to install the Telnet client. The installation process will differ slightly depending on the Windows version you’re using. Generally, we have three main options: 

  • Installing using the command line; 
  • Installing using the PowerShell; 
  • Installing from the Control Panel. 

Installation using the command line 

Press the Windows key or click the Start button. Locate the Start Search box, type cmd, and hit Enter. Right-click on the Command Prompt and press Run as administrator. That way, you’ll have the right to complete the installation. The next step is to dial in a specific command in the command line.

For Windows 7, Windows Server 2008 R2, Windows Server 2008, or Windows Vista, type in the following command and press Enter

pkgmgr /iu:"TelnetClient"

For Windows 8 and above, type in this command and press Enter

dism /online /Enable-Feature /FeatureName:TelnetClient

Wait for the installation to be completed. You should receive a confirmation message on newer versions of Windows OS. 

Installation using PowerShell 

Another option is to use PowerShell to install the Telnet client. However, it’s only applicable to Windows 8.1, Windows 10, Windows Server 2012 R2, or later. 

Open the PowerShell administrator window, type the following command, and press Enter. 

Enable-WindowsOptionalFeature -Online -FeatureName TelnetClient

Wait for the installation to be completed. 

Installation using Control Panel 

Finally, you can install the Telnet client from the Control Panel. To do so, find Programs (or Programs and Features) and open it. Locate Turn Windows features on or off and click on it. You’ll see a Windows Features box. Find Telnet Client and mark the checkbox. Then press OK. Wait for the installation to be completed and restart the computer to apply the changes. 

For other installation options, refer to the Microsoft documentation

Sending the emails 

The email-sending process follows the logic and order of SMTP transmission: handshake, transmission, and termination of the session. It uses SMTP commands and connects to the server through a TCP port. Check out this blog post to find more information on SMTP operation. 

Note: Telnet isn’t a secure way to send an email. It establishes an unencrypted connection, as it doesn’t support SSL or TLS. This means that anyone with access to your network can hijack the transmission and access the contents of your message. 

You can’t connect to SMTP servers with authentication either, as most of them require TLS or SSL encryption before allowing LOGIN and PLAIN authentication methods (authentication without TLS is allowed only on test SMTP servers). You should use OpenSSL instead of Telnet to connect to SMTP servers with encryption. We’ll be talking about OpenSSL below. 

To start an SMTP session, you’ll need the full domain name or the IP address of the SMTP server you’re trying to connect to. For example, if we were to use Mailtrap Email Testing, we’d enter sandbox.smtp.mailtrap.io. 

You’ll also need to identify the port, which can be 25, 587, 465, or 2525. The port number depends on the configurations of the SMTP server you’re trying to connect to. Most SMTP servers block transmissions through port 25. Port 465 is suitable when sending emails with SSL encryption, while port 587 and 2525 should be used with TLS encryption. 

Type the command: 

telnet sandbox.smtp.mailtrap.io 25

Note: You won’t be able to use Mailtrap Email Testing for these purposes in real life as it doesn’t accept Telnet connections through port 25. The code sample above is for illustrative purposes only. 

You’ll see the response starting with code 220 if the connection is successful. For example, 

220 sandbox.smtp.mailtrap.io ESMTP server ready

The next step is to identify yourself to the SMTP host. 

EHLO example.com or HELO example.com

Note: The HELO command will initiate an SMTP connection without service extensions. Therefore, corresponding ESMTP commands (such as STARTTLS, for example) won’t be supported. 

All the supported SMTP extensions will be listed in the response. Each line will start with 250, indicating a successful connection. 

250-sandbox.smtp.mailtrap.io
250-PIPELINING
250-SIZE 10485760
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

Then you can go ahead and transfer the necessary email fields according to the SMTP specification. First, type MAIL FROM, then RCPT TO, and then type DATA.

MAIL FROM: <sender@example.com>
250 2.1.0 Sender OK
RCPT TO: <recipient@example.com>
250 2.1.5 Recipient OK
DATA
354 Start mail input; end with <CRLF>.<CRLF>
From: sender@example.com
To: recipient@example.com
Subject: Telnet email

This is my first test message sent using the Telnet client on Windows
.
250 2.0.0 Ok: queued as ABC123456789

To end the session, you should type the QUIT command. The server will respond with 221 2.0.0 Service closing transmission channel, and the connection will be terminated. 

A complete sample will look something like this: 

telnet sandbox.smtp.mailtrap.io 25
220 sandbox.smtp.mailtrap.io ESMTP server ready
EHLO example.com
250-sandbox.smtp.mailtrap.io Hello
250-SIZE 37748736
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-X-ANONYMOUSTLS
250-AUTH NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 XRDST
MAIL FROM: <sender@example.com>
250 2.1.0 Sender OK
RCPT TO: <recipient@example.com>
250 2.1.5 Recipient OK
DATA
354 Start mail input; end with <CRLF>.<CRLF>
From: sender@example.com
To: recipient@example.com
Subject: Telnet email

This is my first test message sent using the Telnet client on Windows
.
250 2.0.0 Ok: queued as ABC123456789
QUIT
221 2.0.0 Service closing transmission channel

Check this article to get tips to send emails with Telnet on Linux.


Only registered users can post comments. Please, login or signup.

Start blogging about your favorite technologies, reach more readers and earn rewards!

Join other developers and claim your FAUN account now!

Avatar

Daryna Dmytriievska

MArketing Specialist, Railsware

@daryna_dmytriievska
User Popularity
9

Influence

696

Total Hits

4

Posts