Email Server in Delphi with POP3, SMTP, and IMAP Support |
||
Accept Incoming SMTP, POP3, and IMAP ConnectionsThe following three Delphi components implement the low-level Network communication via the SMTP, POP3, and IMAP4 protocols: TclSmtpServer, TclPop3Server, and TclImap4Server. All these components work in a thread pool and keep Emails in memory. Each component provides a set of events, which allow users to handle received data, incoming Emails, and manage user mailboxes. There are the following three Delphi components, which automatically handle all these events and store user data, mailboxes, and Emails on the disk: TclPop3FileHandler, TclIImap4FileHandler, and TclSmtpFileHandler. All you need is to assign the Server property of the File Handler component with a corresponding server instance. After that, you can set up the components' properties, such as MailBox folder, server listening port, UserAccounts collection, and start the server. The SMTP File Handler component looks through incoming Emails and saves messages for local server users to the MailboxDir folder, and outgoing messages to the RelayDir folder.
There are two file types: .MSG and .ENV. A file with .MSG extension keeps a message content, and .ENV file contains information about a message envelope: a sender and recipients. The other File Handler components, TclPop3FileHandler and TclImap4FileHandler, open the MailBoxDir folder, load and manage Emails.
Create User Accounts and Share between Server ComponentsThe introduced project stores information about server settings and user accounts in a .ini file near the application executable. This project is mostly simple demos, and by no means, a completed application. You are free to modify this functionality and implement more secure storage for sensitive data. Since all three server components should share the same user accounts, we can create an instance of the TclMailUserAccountList list and add each user account to this list. After that, we can set up the UserAccounts property of the TclSmtpServer, TclPop3Server, and TclImap4Server components:
Relay Outgoing EmailAs it was mentioned above, the TclSmtpFileHandler component saves outgoing Emails to the RelayDir folder. These messages should be delivered to external recipients on the Internet. The Clever Internet Suite provides a special TclSmtpRelay component, which loads the Email messages together with their envelopes, looks for MX servers using DNS lookup, and, finally, delivers the messages directly to recipients' mailboxes. An instance of the TTimer component on the main form of the program periodically looks through the RelayDir folder and calls the TclSmtpRelay component for each message within this folder. If the message delivery fails, the program moves both the message and it's envelope to the BadDir folder.
Run Email Server in ProductionTo run the Email server in the production environment, the server host must be registered in DNS. There should be at least A and MX records. Otherwise, the server will unable to deliver outgoing Emails, nor accept incoming ones. Using the SMTP protocol, a relay can transfer mail to another process on the same network or to some other network. With SMTP relay, a mail message may pass through a number of intermediate relay or gateway hosts on its path from sender to recipient. The MX mechanisms of the DNS are used to identify the appropriate next-hop destination for a message being transported. A "relay" SMTP system receives mail from an SMTP client and transmits it, without modification to the message data other than adding trace information, to another SMTP server for further relaying or for delivery. See RFC 2821, RFC 2554, and RFC 974 for more details.
Supported compiler versionsThe program can be used in RAD Studio XE3 and higher, including RAD Studio 10.3.3 Rio. If you modify the sources and remove all references to the RAD Studio namespaces in the 'uses' sections, you can use the library in older versions of RAD Studio, CodeGear or Borland Delphi. DownloadsThe program is distributed under the terms of the GNU Lesser General Public License version 3 Download Email Server in Delphi on GitHub Clever Internet Suite Download Learn more about Clever Internet Suite Library
Sergey Shirokov
|