This example shows how to send a custom email at specific intervals from within a Delphi application. The application assumes the use of editable fields such as TEdit components to define the email properties. The advantage to this is that the programmer is able to easily code data validation into the application before executing Febooti Command line email for Windows. It is also possible to extend the application so that the user can schedule email sending.
SOLUTION:
1: After a new application is created in the Delphi IDE the following components should be added:
1.1: TEdit components for email fields such as Subject, Sender, Server, etc. The text from each TEdit component will be used for a specific field of the email. For instance SenderEdit.Text will represent the string that is used for the -SENDER argument in febootimail.
The text for each field can easily be validated during runtime for correctness such as the email address of the receiver containing a @ symbol. It is a good idea for these fields to contain pre-defined values or values which can be stored and retrieved, so they do not need to be typed every time the application is executed.
1.2: A TMemo component for the email body. Other text may also be appended to the string contained in the memo component or this string can be generated at run-time.
1.3: A TTimer component to schedule the task of sending the email. The interval property of the component must be set to a value of 60 seconds as an example. The enabled property should be set to true for the timer to function. This value can also be changed from another component such as a TButton during runtime, should the need arise for the user to start or stop the email schedule.
2: A format string should be defined to make the calling of Febooti Command line email for Windows more convenient. A format string can be defined in Delphi using the Format procedure. The format string required here can be defined as follows for a string variable named cmdStr:
cmdStr = Format('C:\febootimail -SERVER %s -FROM %s -TO %s -SUBJECT %s -MSG %S',
[serverEdit.text, fromEdit.text, toEdit.text, subjectEdit.text, messageMemo.text]);
The format procedure takes a string parameter that is modified using an array of format modifiers and returns the result as a formatted string. String modifiers are defined using %s. Each %s is then replaced with the text from the respective edit field.
3: The following code along with the code for the format string should be appended to the timer's OnTimer event:
uses ShellApi;
...
ShellExecute(Handle, 'open', cmdStr, nil, nil, SW_SHOWNORMAL);
The ShellExecute method is a native Windows method and specific to each version of Windows, thus it may return different error messages on different versions. The developer's documentation should be consulted for specifics of this method, however the above method should work with most versions of Windows.
Once the application has been successfully compiled and is running, provided the enabled property of the TTimer component has been set to true, it will automatically send email to the specified destination using Febooti Windows command line email utility.