My SMTP cheat sheet
321 words, 2 minutes
Today is the day when my SMTP server didn’t want me to relay mail after authentication… This is probably my fault as I may have change something without remembering it. Anyway, here the commands to use to talk SMTP to your favorite server.
Connexion
The “standard” connexion takes place unencrypted on port 25:
# telnet cherie.tumfatig.net 25
Trying 81.56.68.128...
Connected to tumfatig.net.
Escape character is '^]'.
220 cherie.tumfatig.net ESMTP Postfix
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
The connexion can be encrypted with SSL:
# openssl s_client -connect cherie.tumfatig.net:465
The connexion can also be encrypted using STARTTLS:
# openssl s_client -starttls smtp -crlf -connect cherie.tumfatig.net:587
CONNECTED(00000003)
(...)
---
250 DSN
QUIT
DONE
Sending e-mail
This is the usual dialog between a mail client and a mail server:
220 cherie.tumfatig.net ESMTP Postfix
HELO www.tumfatig.net
250 cherie.tumfatig.net
MAIL FROM: <jdoe@tumfatig.net>
250 2.1.0 Ok
RCPT TO: <joel@carnat.net>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
From: ptiJo <jdoe@tumfatig.net>
To: <joel@carnat.net>
Subject: Sending e-mail with the hands
Thank you telnet!
.
250 2.0.0 Ok: queued as BF478261B3
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
Authenticating
Some SMTP servers require you to authenticate before being able to send e-mail.
They will announce AUTH
if you say EHLO
rather than HELO
:
250 DSN
EHLO www.tumfatig.net
250-cherie.tumfatig.net
(...)
250-AUTH PLAIN
(...)
You’d have to use a base64-encoded string of your credentials. You can generate
the string with Perl
:
# perl -MMIME::Base64 -e 'print encode_base64("00userid00userpass")'
AHVzZXJpZAB1c2VycGFzcw==
Then use the string in the authentication process:
(...)
250 DSN
helo www.tumfatig.net
250 cherie.tumfatig.net
auth plain AHVzZXJpZAB1c2VycGFzcw==
235 2.7.0 Authentication successful
mail from: <jdoe@tumfatig.net>
250 2.1.0 Ok
rcpt to: <joel@carnat.net>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
.
250 2.0.0 Ok: queued as A7213261B3
QUIT
DONE
I’m using lowercase commands here because there seem to be issues with
s_client
and uppercase commands.
Here we are ; we can now talk basic SMTP.
That’s All Folks!