Telnet is a simple tool that can be practically used to test open ports on remote hosts, but also could be used to send emails on example.
Testing remote SMTP server reachability
This commands can be executed on Linux and Windows. If you're using Windows, make sure you have Telnet-client programm installed.
To verify that remote SMTP server is reachable to you, open shell prompt and type:
telnet smtp.remote.com 25
If server is reachable and SMTP service is listening port 25 you will see prompt looking like this:
220 smtp.remote.com Microsoft ESMTP MAIL Service ready at Tue, 4 Jun 2019 10:57:16 +0300
This means that SMTP server responded to our connection request.
Sending email
After server prompt received we can submit all required data to form and send email.
To terminate procedure at any time type
quit
.
- Extensions discovery. Most of the servers will require extensions request before proceeding with another commands. Some will require
HELO
instead ofEHLO
.
ehlo smtp.remote.com
Server output:
250-smtp.remote.com Hello [1.2.3.4]
250-SIZE 26214400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-BINARYMIME
250 CHUNKING
2. Set sender address. In this example authentication is not used and we're assuming, that server is working as open relay or authenticates sender by IP address.
mail from: user@remote.com
Server output:
250 2.1.0 Sender OK
3. Set recepient address(es). You can provide one or multiple addresses separated with comma.
rcpt to: admin@remote.com, john.doe@matrix.wld
Server output:
250 2.1.5 Recipient OK
4. Write message body. Make sure you're left one empty line after Subject
and actual body.
data
Server output:
354 Start mail input; end with <CRLF>.<CRLF>
Subject: Test email
Hello! This is a test email message
sent from CLI with Telnet!.
Sincerely,
User
.
Server output:
250 2.6.0 <96da92c9e42c4cccb9363fdada039f95@smtp.remote.com> [InternalId=111355617088758, Hostname=smtp.remote.com] Queued mail for delivery
5. End session by typing quit
quit
Server output:
221 2.0.0 Service closing transmission channel
Connection closed by foreign host.
Server output you're testing with can differ.
Sending email with sender authentication
If your SMTP server requires and support basic authentication (and it's enabled), you can still send emails via telnet.
To do this you will be required to encode login and password with base64 encoding. There is a bunch of online encoders/decoders could be found.
user@remote.com -> dXNlckByZW1vdGUuY29t
SuperStrongPassword -> U3VwZXJTdHJvbmdQYXNzd29yZA==
- Open connection to server
telnet smtp.remote.com
Server output:
220 smtp.remote.com Microsoft ESMTP MAIL Service ready at Tue, 4 Jun 2019 10:57:16 +0300
2. Discover extensions
ehlo smtp.remote.com
Server output:
250-smtp.remote.com Hello [1.2.3.4]
250-SIZE 26214400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-BINARYMIME
250 CHUNKING
3. Ask server to use sender authentication
AUTH LOGIN
Server output:
334 VXNlcm5hbWU6
Enter your encoded username:
dXNlckByZW1vdGUuY29t
Server output:
334 UGFzc3dvcmQ6.
Enter your encoded password:
U3VwZXJTdHJvbmdQYXNzd29yZA==
Server output:
235 2.7.0 Authentication successful
If authentication failed (incorrect login or password, user not exist, etc.) you will receive message:
535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6
If your server isn't supporting basic authentication or it's disabled you will receive something like this:
504 5.7.4 Unrecognized authentication type
4. Continue with mail body
data
Server output:
354 Start mail input; end with <CRLF>.<CRLF>
Subject: Test email with auth
Hello! This is a test email message
sent from CLI with Telnet and authentication!
Sincerely,
User
.
Server output:
250 2.6.0 <96da92c9e42c4cccb9363fdada039f95@smtp.remote.com> [InternalId=111355617088758, Hostname=smtp.remote.com] Queued mail for delivery
5. End session by typing quit
quit
Server output:
221 2.0.0 Service closing transmission channel
Connection closed by foreign host.