Send an email using telnet from remote servers
Introduction
Although modern email systems primarily use authenticated SMTP clients and APIs, Telnet remains a useful tool for testing SMTP connectivity and diagnosing mail server issues. System administrators and DevOps engineers often use Telnet to verify whether an SMTP server accepts connections and processes email commands correctly.
This guide explains how to send a test email using Telnet from a remote Linux server.
Prerequisites
Before starting, ensure that:
- Telnet is installed on the remote server.
- The SMTP server is reachable.
- Port 25, 587, or 465 is open (depending on your mail server configuration).
- The SMTP server allows connections from your server.
To install Telnet:
Ubuntu/Debian
sudo apt update sudo apt install telnet -y
RHEL/CentOS
sudo yum install telnet -y
Step 1: Connect to the SMTP Server
telnet smtp.example.com 25
Example output:
Trying 192.168.1.100... Connected to smtp.example.com. 220 smtp.example.com ESMTP Postfix
Step 2: Introduce Your Server
HELO remote.example.com
Response:
250 smtp.example.com
Step 3: Specify the Sender
MAIL FROM:<sender@example.com>
Expected response:
250 2.1.0 Ok
Step 4: Specify the Recipient
RCPT TO:<recipient@example.com>
Expected response:
250 2.1.5 Ok
Step 5: Start the Email Body
DATA
Response:
354 End data with <CR><LF>.<CR><LF>
Now enter the email:
Subject: SMTP Test Email Hello, This is a test email sent using Telnet from a remote Linux server. Regards, System Administrator .
The period (.) on a separate line indicates the end of the message.
Expected response:
250 2.0.0 Ok: queued as 8A3F112345
Step 6: Close the Connection
QUIT
Response:
221 2.0.0 Bye
Complete Example
telnet smtp.example.com 25 HELO remote.example.com MAIL FROM:<sender@example.com> RCPT TO:<recipient@example.com> DATA Subject: SMTP Test Hello, This email was sent using Telnet. Thank you. . QUIT
Troubleshooting
Connection Refused
telnet: Unable to connect to remote host
Check:
- SMTP service is running.
- Firewall rules.
- Security groups.
- Network routing.
Relay Access Denied
554 Relay access denied
This means your SMTP server does not allow unauthenticated relay. Configure SMTP authentication or whitelist the server.
Connection Timeout
Connection timed out
Verify:
- Port accessibility.
- Firewall configuration.
- ISP restrictions on SMTP traffic.
Testing SMTP Connectivity
To verify connectivity before sending an email:
telnet smtp.example.com 25
or
nc -vz smtp.example.com 25
Example:
Connection to smtp.example.com 25 port [tcp/smtp] succeeded!
Security Considerations
- Telnet sends data in plain text.
- Avoid using Telnet on production SMTP servers requiring authentication.
- For secure email transmission, use SMTP over TLS (port 587) or SMTPS (port 465).
- Use Telnet primarily for troubleshooting and connectivity testing.
Conclusion
Sending email through Telnet is a simple yet powerful method for testing SMTP servers. It helps administrators verify mail server connectivity, identify relay issues, troubleshoot firewall problems, and confirm SMTP functionality without relying on email clients. While it is not intended for production email delivery, Telnet remains an essential diagnostic tool for system administrators
