This page is a how-to that describes how you can transport an email to a SMTP server at the command line using the SMTP protocol for further delivery
It will show you the inner mechanisms of SMTP.
Below is an example of SMTP transaction, if you don't understand it. At the end of this page, you will.
220 eraldy.com ESMTP Eraldy
EHLO Foo
250-eraldy.com
250-8BITMIME
250-SIZE 10240
250-STARTTLS
250-CHUNKING
250 Ok
MAIL FROM:<[email protected]> SIZE=328
250 <[email protected]>... Sender Ok
rcpt to:<[email protected]>
250 <[email protected]>... Recipient Ok
DATA
354 Start mail input; end with <CR><LF>.<CR><LF>
Subject: Hey!
We should meet up! ;)
.
250 Ok
QUIT
221 eraldy.com Service closing transmission channel
The SMTP protocol works via a series of SMTP command between the server and the client.
Each command has:
The server will then respond with a reply code and a human text that defines if the command was successful.
This page shows you how to use the protocol and its commands so that you can transmit an email to a SMTP server.
You will act as a client known as a mail user agent (MUA).
The first step is to connect to the SMTP server.
The port 25 is the default port for a public server and should be configured without TLS
This port is normally only for receiving an email but if you make a connection with the terminal from localhost, it should be permitted to relay the email to the final SMTP server.
Example with:
set localecho
set logfile c:\TelnetTest.txt
telnet localhost 25
With TSL, you use OpenSsl.
The submission port (ie where you can submit an email) is on:
Example:
openssl s_client \
-connect server.example.com:587 \
-servername server.example.com \ # the sni
-crlf
# example with google
openssl s_client -connect smtp.gmail.com:465 -crlf
openssl s_client \
-connect server.example.com:25 \
-starttls smtp \ # start tls
-name hostname \ # the hostname given in the EHLO
-servername server.example.com \ # the sni
-crlf
where:
After a successful connection, the SMTP server responds with a banner
220 smtp.eraldy.com ESMTP Postfix
The remote SMTP client may introduce itself by giving its fully qualified domain name with the EHLO command (Extended HELO)
EHLO client.example.com
The SMTP server answers by advertising its configuration.
250-server.example.com
250-8BITMIME
250-PIPELINING
250-SIZE 10240000
250-AUTH DIGEST-MD5 PLAIN CRAM-MD5
250-CHUNKING
250-ENHANCEDSTATUSCODES
250 SMTPUTF8
...
where:
There are other extensions but they are the common ones.
When you transport a message with SMTP, you create an envelope where
Steps:
Define the sender address (it can be the same than the FROM address header of the email message but it can also be another one)
MAIL FROM:<[email protected]>
250 <[email protected]>... Sender Ok
Enter the recipient (one recipient by line).
RCPT TO: <[email protected]> NOTIFY=success,failure
250 <[email protected]>... Recipient Ok
Note the recipient may be not the TO of the email message. For instance, in the case of a mailing list or group.
Example:
from: [email protected]
reply-to: [email protected]
to: Abridged recipients <[email protected]>
You give the data with the DATA command. After a successful response from the server, you can copy and paste the message.
Steps:
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Subject: Hey!
We should meet up! ;)
.
250 Ok
If you want to exit, you use the QUIT command
QUIT
The server should reply with a 221
221 eraldy.com Service closing transmission channel
You can also transmit another one by resetting the state with the RSET command and starting all over again without quitting
RSET
That's it. You have successfully transported an email to an SMTP server and you have improved your knowledge value. Felicitations.