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
;; QUESTION SECTION:
;example.com. IN MX
;; ANSWER SECTION:
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
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; 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|
|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
250-mx.google.com at your service, [18.104.22.168]
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 Joe@example.com
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!
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.