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 |
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 Trying 74.125.195.26... 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, [162.250.16.236] 250-SIZE 157286400 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 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 DATA 354 Go ahead i9-v6si14369060pgv.109 - gsmtp from: Joe M Joe@example.com Date: 2018/07/02 SUBJECT: Test 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!
Automox for Easy IT Operations
Automox is the cloud-native IT operations platform for modern organizations. It makes it easy to keep every endpoint automatically configured, patched, and secured – anywhere in the world. With the push of a button, IT admins can fix critical vulnerabilities faster, slash cost and complexity, and win back hours in their day.
Grab your free trial of Automox and join thousands of companies transforming IT operations into a strategic business driver.