Complete Mail Server in Delphi, implementing POP, SMTP, IMAP, and Relay |
||
Updated on November 25, 2019 Update NotesThe updated version of the Mail Server program is described in the Email Server in Delphi with POP3, SMTP, and IMAP Support article. The sources are available on GitHub IntroductionThis article demonstrates how to implement a multi-session E-mail Server in Delphi using server Internet components from the Clever Internet Suite library. The provided project represents a fully functional multithreaded Mail Server, which accepts POP3 and IMAP connections, delivers E-mails via the SMTP protocol and relays outgoing E-mails to end-recipients across the Web. IMAP, POP3 and SMTP servicesThe Clever Internet Suite includes all components, which do all the work. No extra libraries are required. The following server components are needed: POP3 Server, IMAP Server and SMTP Server. All these components work with user data (messages and mailboxes) in-memory using special component events. You can handle these events and store mailboxes and their messages to, e.g., a database or the disk. The Clever Internet Suite includes the following three components, which automatically handle all server component events and allow to store user data on the disk like MDaemon, Communigate, and other mail servers: POP3FileHandler, IMAPFileHandler and SMTPFileHandler. Simple link each File Handler component with a corresponding server component and specify the Root Folder to store the user data: Emails, mailboxes, messages.
User AccountsIet's create user accounts and share them between POP3, IMAP, and SMTP server components. This allows us to use the same mailboxes in POP3 and IMAP sessions, send E-mails to local recipients, and accept incoming messages from external senders.
Relay MessagesThere are two kinds of message recipients: local users, which belong to this server, and external users out of the server. When a user sends a message to a local recipient, the message is accepted by the SMTP server. The SMTP server saves received messages locally to a user's mailbox folder. When accepting a message to an external recipient, the SMTP server saves it into a special Relay Folder. You can check out this Relay Folder and deliver all outgoing E-mails to end-recipients. The SMTP Relay component does all the work:
This code utilizes the TTimer VCL component to periodically look through the Relay Queue and run the message delivering process. The SMTP Relay component allows us to easily monitor the delivery status and detect non-delivered E-mails. Download Source CodePlease use the link below to download a full source code for the Mail Server program:
The Mail Server program uses Ini files for saving all server and user account information. This program writes a detailed log about all aspects of IMAP, POP3, and SMTP sessions. The code is constantly refined and improved. Your comments and suggestions are always welcome. Please feel free to Contact Us It will be our pleasure to answer your questions.
Best regards, |