Linux Hack of the Week #5: 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 MX
; <<>> DiG 9.8.3-P1 <<>> 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
;            IN    MX
;; ANSWER SECTION:        231    IN    MX    1        231    IN    MX    10        231    IN    MX    10        231    IN    MX    5        231    IN    MX    5
;; 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 25
Connected to
Escape character is '^]'.
220 ESMTP i9-v6si14369060pgv.109 - gsmtp
EHLO at your service, []
250-SIZE 157286400
250 2.1.0 OK i9-v6si14369060pgv.109 - gsmtp
250 2.1.5 OK i9-v6si14369060pgv.109 - gsmtp
354  Go ahead i9-v6si14369060pgv.109 - gsmtp
from: Joe M
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!

About Automox

Facing growing threats and a rapidly expanding attack surface, understaffed and alert-fatigued organizations need more efficient ways to eliminate their exposure to vulnerabilities. Automox is a modern cyber hygiene platform that closes the aperture of attack by more than 80% with just half the effort of traditional solutions.

Cloud-native and globally available, Automox enforces OS & third-party patch management, security configurations, and custom scripting across Windows, Mac, and Linux from a single intuitive console. IT and SecOps can quickly gain control and share visibility of on-prem, remote and virtual endpoints without the need to deploy costly infrastructure.

Experience modern, cloud-native patch management today with a 15-day free trial of Automox and start recapturing more than half the time you're currently spending on managing your attack surface. Automox dramatically reduces corporate risk while raising operational efficiency to deliver best-in-class security outcomes, faster and with fewer resources.

Dive deeper into this topic