Test SMTP/IMAP(S)/POP3(S) configuration from the command line
In this post, I will show the full command line to test the SMTP/IMAP/POP3 server from the local command line.
SMTP server
There are 2 types of configuration, one requires STARTTLS and one does not.
A typical configuration has the following fields. Replace them with your configuration appropriately.
- SMTP server:
smtp.example.com
- Port:
587
- Username:
transang@example.com
- Password:
mysecuredpassword
- Require STARTTLS: true or false
Send an email via the SMTP server
You want to send a test email to the email test@gmail.com
If the SMTP server does not require STARTTLS
- Step 1:
telnet smtp.example.com 587
- Step 2: type
EHLO smtp.example.com
then pressEnter
- Step 3: type
AUTH LOGIN
then pressEnter
- Step 4:
(Optional) After the previous step, the server would return334 VXNlcm5hbWU6
(Optional) Open Javascript console, run commandatob('VXNlcm5hbWU6')
to make sureVXNlcm5hbWU6
is base64-decoded toUsername:
which means the server request for the username
In Javascript console, run commandbtoa('transang@example.com')
to get resultdHJhbnNhbmdAZXhhbXBsZS5jb20=
, which is a base64-encoded string of the username in your configuration - Step 5: go back to the telnet console, type
dHJhbnNhbmdAZXhhbXBsZS5jb20=
, then pressEnter
- Step 6: similar to step 4
(Optional) After the previous step, the server would return334 UGFzc3dvcmQ6
which meansPassword:
after base64-encoded
In Javascript console, run commandbtoa('mysecuredpassword')
to get resultbXlzZWN1cmVkcGFzc3dvcmQ=
, which is a based64-encoded string of the password in your configuration - Step 7: go back to the telnet console, type
bXlzZWN1cmVkcGFzc3dvcmQ=
, then pressEnter
- Step 8:
(Optional) Server would return235 2.0.0 OK Authenticated
after the previous step
TypeMAIL FROM: transang@example.com
, then pressEnter
- Step 9:
(Optional) server would return250 2.1.0 transang@example.com... Sender ok
TypeRCPT TO: test@gmail.com
, then pressEnter
- Step 10:
(Optional) server would return250 2.1.5 test@gmail.com... Recipient ok
TypeDATA
, then pressEnter
- Step 11: type
Subject: This is subject of the test email
, then pressEnter
- Step 12: press
Enter
again - Step 13: Type content of the email body with or without the newline string. For example type
This is body of the test email
, then pressEnter
- Step 14: Finish and send an email by a single line with
.
, then pressEnter
- Step 15: type
QUIT
, then pressEnter
Now open your inbox of the test email test@gmail.com
to check if the test email has been sent
If the SMTP server requires STARTTLS.
For example Gmail server at smtp.gmail.com
- Step 1:
openssl s_client -starttls smtp -connect smtp.example.com:587
- The following steps are the same as in the previous section (step 1 to step 15)
Q/A
- What does the 3 digit-number mean at the beginning of messages from the server? For example
334
,235
,250
.
They are called SMTP codes. Refer to their meaning here: https://serversmtp.com/smtp-error/. - How to know if SMTP requires/supports STARTTLS?
Following the procedure in the first section, i.e., pretend the server does not require STARTTLS.
After step 3 (typeAUTH LOGIN
, then pressEnter
).
If the server returns334 VXNlcm5hbWU6
, which means that the server does not require STARTTLS.
If the server returns530 5.7.0 Must issue a STARTTLS command first. e65sm6419106pfc.184 - gsmtp
, which means that the server requires STARTTLS.
Otherwise, the server returns other values. Please comment and let me know. - How to check which SSL cipher types does the server support?
Use commandnmap --script ssl-enum-ciphers -p 587 smtp.example.com
ornmap --script ssl-enum-ciphers -Pn -p 587 smtp.example.com
. - There is also a package named
telnet-ssl
which supports telnet via SSL channel.
Use commandtelnet-ssl -z ssl smtp.example.com 465
Then usectrl-]
menu to activatestarttls
if required.
Source:
- https://superuser.com/a/346962
- https://stackoverflow.com/a/32671806/1398479
- https://docs.microsoft.com/en-us/exchange/mail-flow/test-smtp-with-telnet?view=exchserver-2019
- https://www.ndchost.com/wiki/mail/test-smtp-auth-telnet
- https://security.stackexchange.com/a/70737/155319
Send an email to an SMTP server
- Step 1:
telnet smtp.example.com 587
- Step 2: type
HELO smtp.example.com
then pressEnter
(Note: useHELO
instead ofEHLO
) - Skip steps 3, 4, 5, 6, 7
- Do all steps from step 8
Test IMAP server
The server does not have TLS/SSL
telnet imap.example.com 143
. USER <username> <password>
(notice the leading dot). LIST "" "*"
(notice the leading dot)Ctrl + ]
to quit
The server requires TLS/SSL
openssl s_client -connect imap.example.com:993
- All steps are the same as above
Test POP3 server
The server does not have TLS/SSL
telnet pop3.example.com 110
USER <username>
PASS <password>
LIST
QUIT
to quit
The server requires TLS/SSL
openssl s_client -connect pop3.example.com:995
- All steps are the same as above