Linux Hacks

Linux Hack of the Week #5: Sending Emails with Telnet

By July 6, 2018 No Comments
Sending emails with telnet

In this week’s installment of Linux tips and tricks, I will demonstrate how to use SMTP with telnet to send emails.

Step 1: Determine the Mail Server

You need to know your domain’s mail server. To do that, perform a lookup of the MX (mail exchanger) record:

joes-MacBook-Pro:~ joe$ dig example.com MX

; <<>> DiG 9.8.3-P1 <<>> example.com MX

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31782

;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0


;example.com.            IN    MX


example.com.        231    IN    MX    1 aspmx.l.google.com.

example.com.        231    IN    MX    10 alt3.aspmx.l.google.com.

example.com.        231    IN    MX    10 alt4.aspmx.l.google.com.

example.com.        231    IN    MX    5 alt1.aspmx.l.google.com.

example.com.        231    IN    MX    5 alt2.aspmx.l.google.com.

;; Query time: 2 msec


;; WHEN: Mon Jul  2 13:00:56 2018

;; MSG SIZE  rcvd: 144

This tells us to use any of the 5 MX servers listed above.

Step 2: Read the RFC

SMTP is defined in RFC 5322 and RFC 2821. I’ll give you the commands you need in this post. However, if you want to access the full documents, they live here:

EHLO This tells the mail server the name of the client sending the message
MAIL FROM Who the message is from
RCPT TO Who the message is to
DATA Message data
 from Extended from, including name
 date Date the message is from
 subject The subject line

End your message with a single dot on a line. An example is shown below:

joes-MacBook-Pro:~ joe$ telnet aspmx.l.google.com 25


Connected to aspmx.l.google.com.

Escape character is ‘^]’.

220 mx.google.com ESMTP i9-v6si14369060pgv.109 – gsmtp

EHLO example.com

250-mx.google.com at your service, []

250-SIZE 157286400







MAIL FROM:<joe@example.com>

250 2.1.0 OK i9-v6si14369060pgv.109 – gsmtp

RCPT TO:<joe@example.com>

250 2.1.5 OK i9-v6si14369060pgv.109 – gsmtp


354  Go ahead i9-v6si14369060pgv.109 – gsmtp

from: Joe M Joe@example.com

Date: 2018/07/02


This is a test


250 2.0.0 OK 1530559026 i9-v6si14369060pgv.109 – gsmtp

451 4.4.2 Timeout – closing connection. i9-v6si14369060pgv.109 – gsmtp

Connection closed by foreign host.

This is a great way for you to test if your mail server is working, if it accepts spam, and so on. I have been using this little trick for years, and hopefully it will help you out too!


Joe McManus

Author Joe McManus

Joe is a Senior Cyber Security Researcher at CERT and a Professor at the University of Colorado College of Engineering where he teaches graduate courses in information security and forensics. Recently, Joe was the Director of Security at SolidFire, (acquired by NetApp [NTAP]). He is an avid cyclist, climber and leads the Automox security team.

More posts by Joe McManus

Leave a Reply