Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Using Telnet with SMTP

From John's Wiki

The Old Way

To connect to a server using Telnet you would run the following command.

telnet mail.example.com 25

However, you're not going to get very far. Unencrypted Telnet is a no-no for most mail servers and they'll cut you off right there.

Using OpenSSL to Connect Securely

Luckily, you can get around this by using the wonderful openssl tool/library to wrap your telnet session in a warm security blanket weaved from the finest encryption the transport security layer has to offer.

  • To connect to a mail server using openssl:
openssl s_client -connect mail.example.com:25 -starttls smtp -no_ssl3
  • Next say hello with your domain name:
helo DOMAIN.COM
  • To send a message:
mail from: from@example.com
  • Enter the recipient:
rcpt to: to@example.com

You may not be able to send to anyone except for yourself this way because most mail providers will not allow you to send without first authenticating. You'll know you're not allow to send externally because you'll get a 554 5.7.1 Relay access denied error.

  • Type data to begin composing your message and . to end
data
354 End data with <CR><LF>.<CR><LF>
Subject: Test Email with telnet

Hey me, 

I was able to send an email with telnet
.

Authentication

  • To authenticate before sending you'll need to run:
AUTH PLAIN
  • Then you'll need to enter a base64 encoded string version of your username and password:
USERNAMEUSERNAMEPASSWORD (in base64)
  • Then you'll be authenticated to send:
235 2.7.0 Authentication successful

You can generate the base64 encoded username/password string with the following:

echo -ne "USER@DOMAIN.TLD\x00USER@DOMAIN.TLD\x00PASSWORD" | base64 --wrap=0

Where USER@DOMAIN.TLD is your Email address and PASSWORD is your mailbox password.

You can also find the correct base64 encoding of the "username\x00username\x00password" string is by grabbing it out of the verbose output of the SMTP handshake that happens when you're Sending an Email with Curl. This form of SASL PLAIN auth string will always be "username\x00username\x00password" as described in RFC4616

PLAIN SASL Mechanism

  The mechanism consists of a single message, a string of [UTF-8]
  encoded [Unicode] characters, from the client to the server.  The
  client presents the authorization identity (identity to act as),
  followed by a NUL (U+0000) character, followed by the authentication
  identity (identity whose password will be used), followed by a NUL
  (U+0000) character, followed by the clear-text password.

Sources

https://hostpapasupport.com/view-send-email-using-telnet/

https://michlstechblog.info/blog/mail-connect-tls-encrypted-to-a-smtp-server-by-telnet/

https://tools.ietf.org/html/rfc4616