SMTP – Telnet or OpenSSL

One day I was creating a SMTP client and faced some issues or poor documentation about how to simple send a e-mail using a command line tool, to be able to test the server and compare the results with my code to minify the problems.

Most of the protocols like SMTP, HTTP are simple TCP clients, in some cases with SSL, to connect i normally use ‘telnet’, and with SSL I use ‘openssl’.

Requirements

To use ‘telnet’ or ‘openssl’, both need to be installed. In some distros like Linux or FreeBSD they come installed.

To install then manually

$ sudo apt-get install telnet openssl
# or 
$ sudo yum install telnet openssl
# FreeBSD
$ pkg install telnet openssl
# MACOS - Homebrew
$ brew install telnet openssl

Connection

Most servers use port 25, 465 and 587.
Port 25 – Plain
Port 465 – SSL
Port 587 – SSL/TLS

To connect to the server using telnet

# telnet {host} {port}
$ telnet smtp.domain.com 25

To connect using openssl

# SSL
$ openssl s_client -connect smtp.domain.com:465
# SSL/TLS
$ openssl s_client -starttls smtp -connect smtp.domain.com:587

Commands

After connecting, we can use the protocol to send a e-mail

-- First we ourself
EHLO sender.brbyte.com

--- Start authorization
AUTH LOGIN

--- Send Username
ZmVybmFuZG9Ac29mdG92LmNvbS5icg==

--- Send Password
cGFzc3dvcmQ=

--- Start E-mail
MAIL FROM: <fernando@softov.com.br>

--- Set Destination
RCPT TO: <softov@brbyte.com>

--- Start Data
DATA

--- Send Content
MIME-Version: 1.0
FROM: TESTE <fernando@softov.com.br>
TO: SOFTOV <softov@brbyte.com>
SUBJECT: TESTE assunto
Content-Type: text/plain; charset=UTF-8; format=flowed

Testing e-mail

.

--- Finished

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *