A downloadable file for this article (for purposes of testing) is available here. A downloadable zip of the source code is also available here.
An SMTP Server stores mail messages in an ordered way. The server gets the messages from an SMTP Client. For example, if you create and send a new message from a mail client such as Eudora or Outlook Express, an SMTP Client will carry this message to an SMTP Server associated with the domain in a mail address.
A typical email address consists of a name and domain name i.e., email@example.com, so the sending client will transport the message to the receiving server. The server will then store the message, so that a pop3 server can retrieve it later. To summarize, the purpose of an SMTP Server is to store messages received from SMTP Clients. If you want to learn more about pop3 servers, check out my article here; it's a companion piece to this one.
Aims of the Application
Like any communications protocol, the SMTP Server communicates through commands and replies. So in this tutorial we will implement all the commands that are needed to create a fully functional SMTP Server. The following commands are needed:
USERNAME PASSWORD MAIL FROM RCPT TO DATA
What you need
If you have Delphi 6 and above, then you can skip this section; otherwise go to http://www.indyproject.org/ and download the version appropriate to your Delphi version. I am using Delphi 7 and Indy 10.1.15. There are proper guides available on the indy site that explain how to install Indy on your computer.
Let's get started
Start Delphi, and create a new application. Drop the following components on the form: