How to Send an Email Using Telnet from a Remote Server

Introduction

Email delivery issues can sometimes be difficult to diagnose, especially when dealing with SMTP authentication errors, firewall restrictions, mail server configuration problems, or relay issues. One of the most effective troubleshooting techniques is sending an email directly through an SMTP server using Telnet.

By communicating with the mail server manually, administrators can verify SMTP connectivity, test authentication credentials, confirm mail routing, and identify potential delivery problems without relying on an email client.

This guide explains how to send an email using Telnet from a remote server and how to use the process for email troubleshooting.


Prerequisites

Before starting, ensure that:

  • Telnet is installed on the server.
  • You have valid SMTP credentials.
  • You know the SMTP hostname and port.
  • Outbound SMTP connections are allowed by the firewall.
  • The mail server supports SMTP AUTH LOGIN authentication.

Step 1: Convert SMTP Credentials to Base64

SMTP AUTH LOGIN requires the username and password to be encoded in Base64 format.

Use the following Perl commands:

perl -MMIME::Base64 -e 'print encode_base64("test\@domainname.com")'

Example output:

dGVzdEBkb21haW5uYW1lLmNvbQ==

Convert the password:

perl -MMIME::Base64 -e 'print encode_base64("password")'

Example output:

cGFzc3dvcmQ=

Note: If your username contains special characters such as @, escape them using a backslash (\) when required by the shell.

Save both Base64 values for later use.


Step 2: Connect to the SMTP Server

Use Telnet to connect to the mail server.

telnet mail.servername.com 25

Example successful response:

220 mail.servername.com ESMTP

This confirms that the SMTP service is reachable.


Step 3: Introduce Yourself to the SMTP Server

Send the EHLO command:

EHLO servername

Example response:

250-mail.servername.com
250-AUTH LOGIN PLAIN
250 SIZE 52428800

The server will display supported SMTP features and authentication methods.


Step 4: Begin SMTP Authentication

Start authentication:

AUTH LOGIN

Server response:

334 VXNlcm5hbWU6

This is the Base64 prompt for the username.

Enter the Base64-encoded username generated earlier:

dGVzdEBkb21haW5uYW1lLmNvbQ==

The server will respond:

334 UGFzc3dvcmQ6

This is the Base64 prompt for the password.

Enter the Base64-encoded password:

cGFzc3dvcmQ=

Successful authentication response:

235 Authentication succeeded

Step 5: Send the Email

After authentication, enter the following SMTP commands:

MAIL FROM:<sender@domain.com>
RCPT TO:<recipient@example.com>
DATA

The server will respond:

354 End data with <CR><LF>.<CR><LF>

Enter the message content:

Subject: Test Email

This is a test email sent using Telnet.

.

The period (.) on a separate line indicates the end of the message.

Successful response:

250 Message accepted for delivery

Step 6: Close the SMTP Session

Terminate the session:

QUIT

Response:

221 Bye

The email should now be delivered to the recipient mailbox.


Example SMTP Session

telnet mail.servername.com 25

EHLO servername

AUTH LOGIN

dGVzdEBkb21haW5uYW1lLmNvbQ==

cGFzc3dvcmQ=

MAIL FROM:<sender@domain.com>

RCPT TO:<recipient@example.com>

DATA

Subject: Test Email

This is a test email.

.

QUIT

Why Use Telnet for Email Troubleshooting?

Using Telnet allows administrators to:

  • Verify SMTP connectivity.
  • Test SMTP authentication.
  • Check relay permissions.
  • Validate sender and recipient addresses.
  • Troubleshoot firewall issues.
  • Identify SMTP rejection messages.
  • Test mail flow without using Outlook or webmail.

Because responses are displayed immediately, SMTP errors can be diagnosed much faster than through traditional email clients.


Common SMTP Errors

Authentication Failed

535 Authentication failed

Possible causes:

  • Incorrect username
  • Incorrect password
  • Improper Base64 encoding

Relay Access Denied

554 Relay access denied

Possible causes:

  • Authentication not completed
  • Server does not allow relaying

Connection Refused

Connection refused

Possible causes:

  • SMTP service is down
  • Firewall blocking the port
  • Wrong hostname or port

Conclusion

Sending email through Telnet is a simple yet powerful technique for diagnosing SMTP issues and validating mail server functionality. By manually connecting to the SMTP service, authenticating with Base64 credentials, and issuing SMTP commands, administrators can quickly determine whether email delivery problems originate from authentication failures, relay restrictions, DNS issues, or server configuration errors. This method remains one of the most effective troubleshooting tools for mail server administrators and support engineers.


Frequently Asked Questions (FAQ)

1. Why do I need to convert credentials to Base64?

SMTP AUTH LOGIN expects usernames and passwords to be transmitted in Base64 format during the authentication process. This is a standard SMTP authentication requirement.


2. Can I use Telnet on SMTP port 587?

Yes. Many mail servers accept SMTP authentication on port 587.

Example:

telnet mail.servername.com 587

However, some servers require STARTTLS encryption before authentication.


3. Is Telnet suitable for production email sending?

No. Telnet is primarily a troubleshooting and testing tool. For regular email delivery, use an email client, SMTP library, or application framework that supports secure authentication and encryption.


  1. Create an Email Account in cPanel
    Learn how to create, manage, and configure email accounts using the cPanel interface.
    Create an Email Account in cPanel
  2. Script to Identify Bounce Back Emails
    Automatically detect and analyze bounced email messages to troubleshoot delivery issues and improve email reliability.
    Script to Identify Bounce Back Emails
  3. Send Email Using HTML Templates in CodeIgniter
    Learn how to create professional email templates and send HTML emails using the CodeIgniter framework.
    Send Email Using HTML Templates in CodeIgniter

 

admin

Writes about Cloud & AWS at Pheonix Solutions.

Leave a Reply

Scroll to Top