In this post, I will show full command line to test a SMTP connection.

There are 2 types of configuration, one requires STARTTLS and one does not.

Typical configuration has 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

You want to send test email to the email test@gmail.com


If SMTP server does not require STARTTLS

  • Step 1: telnet smtp.example.com 587
  • Step 2: type EHLO smtp.example.com then press Enter
  • Step 3: type AUTH LOGIN then press Enter
  • Step 4:
    (Optional) After previous step, server would return 334 VXNlcm5hbWU6
    (Optional) Open Javascript console, run command atob('VXNlcm5hbWU6') to make sure VXNlcm5hbWU6 is base64-decoded to Username: which means the server request for the username
    In Javascript console, run command btoa('transang@example.com') to get result dHJhbnNhbmdAZXhhbXBsZS5jb20=, which is base64-encoded string of the username in your configuration
  • Step 5: go back to telnet console, type dHJhbnNhbmdAZXhhbXBsZS5jb20=, then press Enter
  • Step 6: similar to step 4
    (Optional) After previous step, server would return 334 UGFzc3dvcmQ6 which means Password: after base64-encoded
    In Javascript console, run command btoa('mysecuredpassword') to get result bXlzZWN1cmVkcGFzc3dvcmQ=, which is based64-encoded string of the password in your configuration
  • Step 7: go back to telnet console, type bXlzZWN1cmVkcGFzc3dvcmQ=, then press Enter
  • Step 8:
    (Optional) Server would return 235 2.0.0 OK Authenticated after the previous step
    Type MAIL FROM:<transang@example.com>, then press Enter
  • Step 9:
    (Optional) server would return 250 2.1.0 transang@example.com... Sender ok
    Type TCPT TO:<test@gmail.com> NOTIFY=success,failure, then press Enter
  • Step 10:
    (Optional) server would return 250 2.1.5 test@gmail.com... Recipient ok
    Type DATA, then press Enter
  • Step 11: type Subject: This is subject of the test email, then press Enter
  • Step 12: press Enter again
  • Step 13: Type content of the email body with or without new line string. For example: type This is body of the test email, then press Enter
  • Step 14: Finish and send email by a single line with ., then press Enter
  • Step 15: type QUIT, then press Enter

Now open your inbox of the test email test@gmail.com to check if the test email has been sent


If SMTP server does not require 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 same as in previous section (step 1 to step 15)

Q/A

  • What does 3 digit-number mean in the beginning of messages from server? For example 334, 235, 250
    They are called SMTP code. Refer to their meaning here: https://serversmtp.com/smtp-error/
  • How to know if SMTP require/support STARTTLS?
    Following procedure in the first section, i.e., pretend the server does not require STARTTLS.
    After step 3 (type AUTH LOGIN, then press Enter)
    If server returns 334 VXNlcm5hbWU6, which means that the server does not require STARTTLS
    If server returns 530 5.7.0 Must issue a STARTTLS command first. e65sm6419106pfc.184 - gsmtp, which means that the server requires STARTTLS
    Otherwise, server returns other values. Please comment and let me know
  • How to check which ssl cipher types does the server support?
    Use command nmap --script ssl-enum-ciphers -p 587 smtp.example.com
    or nmap --script ssl-enum-ciphers -Pn -p 587 smtp.example.com
  • There is also a package named telnet-ssl which support telnet via ssl channel
    Use command telnet-ssl -z ssl smtp.example.com 465
    Then use ctrl-] menu to to activate starttls if required

Source: