Sending email with telnet

Jared Shah
Jared Shah
Developer @MailSlurp
  • Table of contents

How to send email with telnet mail commands from the terminal. Use the telnet protocol to interact with SMTP mail servers.

send email with telnet smtp

Telnet is an internet protocol providing command line access to servers. Telnet can be used to connect to email mail servers and send emails. This article will show you how.

Installing telnet

Telnet comes with most Linux and Mac systems. On Windows machines you must enable telnet in the control panel programs and features section.

telnet

Connecting to a mail server

First step is to open a terminal or command line (such as powershell). Then type:

telnet mx.mailslurp.com 2525

Here we connect to the MailSlurp email server but you can replace mx.mailslurp.com with any SMTP server. The second argument (2525) is the port. Typically, email servers run on port 25 or 2525. Use dig to lookup DNS nameservers if you don't know an SMTP server host.

Say hello!

Once connect you must say hello using the helo command:

helo yourname

If successful you will see a reply such as:

250 2.0.0 Hello yourname

Sending a message

Mail from command

Telnet is a step-by-step process. You must instruct the server who is sending the email and to whom. Say you are sending an email to the server from test@test.com, run the following command:

mail from: test@test.com

The server will respond with OK if it accepts your mail sender:

250 2.1.0 Sender OK

Rcpt To

Next you must specify the recipient of the email using rcpt to.

rcpt to: dog@doggies.net

The server will respond:

250 2.1.5 Recipient OK

Data and subject

Next we can set the subject and the body of the message.

subject: this is the subject

For the data we use the data command and end our message with a new line and full stop.

data
this is my message
.

What about receiving mail?

You can also read emails with telnet, provided you have login credentials. Use the user and pass commands to login with your SMTP username and password.

List command

Use list once logged in to list emails. Each email is given a number. Use the number to read each message using the retr command.

Retr (for retrieve)

Use retr email_number to view the email by giving the number of the email that you obtained from the list.

BCC and CC

For more options see the BCC and CC SMTP guide.

Email and SMS Platform
Create a free account in 3 clicks