Clever Mailer for RAD Studio
The algorithm of the mailer program is simple:
Lets go ahead and consider each of these steps in details.
Read configuration information
The program uses a special configuration file in "ini" format. So we can use the TIniFile class for loading this information:
The message body can be represented in text, HTML or both formats. Each message body part is loaded from the file on the disk. The recipient list is loaded from the file as well.
You may need to substitute the name of the recipient to the message body before sending. The TclEmailAddressItem class from Clever Internet Suite allows you to extract the name part from the fully qualified email address information:
Set up the DKIM component
The DKIM component requires the following information for signing the message: domain, selector and a private key. This information is loaded from the configuration file and from the specified key file in the "pem" format. The detailed description for the domain and selector parameters can be found in the DKIM standard RFC 6376
The key information represents the private part of the public / private key pair that is specific to the sender's domain. If you don't have a key, you can generate it with the DKIM component from the Clever Internet Suite library. A sample of this functionality can be found in the DkimSign demo. You can download it from the Clever Internet Suite Download page.
Loop through the recipient list and send mail
After the whole data is ready and the components are configured, you can loop through the recipient list and send mail to each of them. There is one important moment: you need to check whether the message has been aready sent before starting the process. Otherwise, the message may be sent twice or more times.
The sending status can be stored in a report file for further analyzing. Note, the sending status may differ from the delivery status. The sending status indicates that the message was sent successfully at the client side. The most of email services may initially accept the email message, but not deliver to the recipient's mailbox. There may be different reasons why the message is not delivered: email filtering, mailbox unavailable, mailbox is full, etc. In such a case, you receive the non-delivery report. This report is sent by the email service to the sender's mailbox. The analysis of these non-delivery reports is out of scope of this article. We will consider this task in the next article. This functionality may be implemented with the BounceChecker component of the Clever Internet Suite library.
Supported compiler versions
Clever Mailer for RAD Studio can be used in RAD Studio XE3 and higher, including RAD Studio 10.1 Berlin. 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.
Download source code
The current version of Clever Mailer for RAD Studio needs for the non-free library Clever Internet Suite. This is a drawback, and we suggest the task of changing the program so that it does the same job without the non-free library. Anyone who thinks of doing substantial further work on the program, first may free it from dependence on the non-free library. The class structure allows you to easily replace the Clever Internet Suite MailMessage, Smtp and Dkim components with any other third-party free and non-free software.
Please feel free to Contact us if you need any assistance.