How to send email with telnet mail commands from the terminal. Use the telnet protocol to interact with SMTP mail servers.
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.
Telnet comes with most Linux and Mac systems. On Windows machines you must enable telnet in the control panel programs and features section.
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.
Once connect you must say hello using the
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 email@example.com, run the following command:
mail from: firstname.lastname@example.org
The server will respond with OK if it accepts your mail sender:
250 2.1.0 Sender OK
Next you must specify the recipient of the email using
rcpt to: email@example.com
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
pass commands to login with your SMTP username and password.
list once logged in to list emails. Each email is given a number. Use the number to read each message using the
Retr (for retrieve)
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.