Mail: Connect TLS encrypted to a smtp server by telnet

Hi,

the SMTP protocol is ASCII based. In the past, the SMTP protocol goes unencrypted over the wire means you can simply send emails by connecting to the SMTP port 25 and enter some SMTP commands via telnet:

michael@debdev ~ # telnet smtp.yourdomain.org 25
EHLO test.example.com
MAIL FROM:info@yourdomain.org
RCPT TO:receiver@receiversdomain.org
DATA
Subject: Testmessage
<ENTER>
<ENTER>
This is a test message. End with <ENTER><ENTER> and point

.
QUIT


Many provider does no longer accept such plain text connections. You can use openssl instead. Connect to Port 25 to your SMTP server and said Hello (EHLO).

michael@debdev ~ # openssl s_client -connect smtp.yourdomain.org:25 -starttls smtp -no_ssl3
250-smtp.yourdomain.org greets 10.254.1.54
250-PIPELINING
250-8BITMIME
250-DELIVERBY
250-SIZE 104857600
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-BURL imap
250-CHUNKING
250 HELP

EHLO michael
AUTH LOGIN
334 VXNlcm5hbWU6

If connected the SMTP server asks for your username and password (Base64 decoded: VXNlcm5hbWU6 => username: / UGFzc3dvcmQ6 => password:). You must provide the username and password as UTF8 strings base64 encoded. You can use python or powershell to encode the strings ad requested.

The powershell way

PS C:\> [string]$sStringToEncode="mymailaddress@yourdomain.org"
PS C:\> $sEncodedString=[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($sStringToEncode))
PS C:\> write-host "Encoded String:" $sEncodedString
Encoded String: bXltYWlsYWRkcmVzc0B5b3VyZG9tYWluLm9yZw==
# Or as oneliner
PS C:\> [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("mymailaddress@yourdomain.org"))
bXltYWlsYWRkcmVzc0B5b3VyZG9tYWluLm9yZw==

And with python

>>> import base64
>>> Base64String=base64.encodestring("mymailaddress@yourdomain.org")
>>> print Base64String
bXltYWlsYWRkcmVzc0B5b3VyZG9tYWluLm9yZw==

Send the Username

AUTH LOGIN
334 VXNlcm5hbWU6
bXltYWlsYWRkcmVzc0B5b3VyZG9tYWluLm9yZw==

and the Password

334 UGFzc3dvcmQ6
TXlWZXJ5U2VjdXJlUGFzc3dvcmQ=
235 Authentication succeeded

Send a mail.
Note: Use lower case characters otherwise your session terminates with Error: “RENEGOTIATING 1991292344:error:140670F5:SSL routines:SSL3_READ_BYTES:unexpected record:s3_pkt.c:1467” because theSee CONNECTED COMMANDS triggers a renegotiate when the first character in line is a upper “R” or a lower “q”.

mail from:info@yourdomain.org
250 OK
rcpt to:receiver@receiversdomain.org
250 Accepted
DATA
354 Enter message, ending with "." on a line by itself
To: My User Friendly Name<info@yourdomain.org>
From: The Receivers friedly name <receiversdomain.org>
Subject: Testmessage
This is a test message. End with <ENTER><ENTER> and a dot

.
250 OK id=2rAXnz-0232Su-AB
QUIT

Michael

2 thoughts on “Mail: Connect TLS encrypted to a smtp server by telnet”

Leave a Reply