Note: This is not the complete source code--just the main source file.
You can download the full source (with include files) from our sample code archive by clicking on the diskette icons.
unit SimpleEAV; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, HexValidEmailLib; type TForm1 = class(TForm) Label1: TLabel; editEmail: TEdit; btnValidate: TButton; btnExit: TButton; memoResult: TMemo; Label2: TLabel; procedure btnExitClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure btnValidateClick(Sender: TObject); private { Private declarations } public { Public declarations } end; function GetErrorString( error: Integer ): String; function GetLicenseErrorString( error: Integer ) : String; var Form1: TForm1; hve: IConnectionSync; implementation {$R *.dfm} procedure TForm1.btnExitClick(Sender: TObject); begin Application.Terminate(); end; procedure TForm1.FormCreate(Sender: TObject); begin // Create an instance hve := CoConnection.CreateLicensed( 'Put your runtime key here' ); // Identify yourself for SMTP (use your own information here) // See http://www.hexillion.com/docs/guides/HexValidEmail/concepts/polite_usage.htm hve.FromDomain := 'hexillion.com'; // The domain name of your machine hve.FromEmail := 'HexValidEmail@hexillion.com'; // Email address of technical contact person // Set timeouts (optional) hve.Timeouts.Item(hexVeTimeoutDnsTotal).Value := 4000; hve.Timeouts.Item(hexVeTimeoutSmtpTotal).Value := 30000; memoResult.Text := ''; end; procedure TForm1.btnValidateClick(Sender: TObject); var iRating: Integer; sOut: String; begin btnValidate.Enabled := false; // Do the validation to SMTP level iRating := hve.Validate( editEmail.Text, hexVeLevelSmtp ); sOut := editEmail.Text + #13#10; // If the address is definitely bad... if (hexVeLevelBad = iRating) then // Display the reason why sOut := sOut + 'Bad address: ' + GetErrorString(hve.Error) // If validation didn't reach intended level... else if (iRating < hexVeLevelSmtp) then // Say why sOut := sOut + Format( 'No problems were found with the address, ' + 'but the validation failed at level %d ' + 'with the following error: %s', [iRating+1, GetErrorString(hve.Error)] ) else // No problems encountered sOut := sOut + 'No problems were found with the address.'#13#10'That does not guarantee it is good.'; memoResult.Text := sOut; btnValidate.Enabled := true; end; // Gets message strings based on HexValidEmail error codes function GetErrorString( error: Integer ): String; begin case error of hexVeErrTimedOut: Result := 'Timed out'; hexVeErrConnectionRefused: Result := 'Connection refused'; hexVeErrConnectionReset: Result := 'Connection reset'; hexVeErrHostUnreachable: Result := 'Host unreachable'; hexVeErrAddressNotAvailable: Result := 'Address not available'; hexVeErrNetworkDown: Result := 'Network down'; hexVeErrNetworkUnreachable: Result := 'Network unreachable'; hexVeErrConnectionAborted: Result := 'Connection aborted'; hexVeErrHostNotFound: Result := 'Host not found'; hexVeErrTryAgain: Result := 'Try again'; hexVeErrNoRecovery: Result := 'No recovery'; hexVeErrNoData: Result := 'No data'; hexVeErrUnexpected: Result := 'Unexpected error'; hexVeErrAddrTooLong: Result := 'Address too long'; hexVeErrExtraTextPresent: Result := 'Extra text is present'; hexVeErrIllegalChar: Result := 'Illegal character'; hexVeErrUnbalancedParenthesis: Result := 'Unbalanced parenthesis'; hexVeErrUnbalancedSquareBracket: Result := 'Unbalanced square bracket'; hexVeErrUnbalancedAngleBracket: Result := 'Unbalanced angle bracket'; hexVeErrQuotationMarksNotClosed: Result := 'Quotation marks not closed'; hexVeErrDomainLiteralPresent: Result := 'A domain literal is present'; hexVeErrMisplacedDomainLiteral: Result := 'Misplaced domain literal'; hexVeErrMisplacedQuotedString: Result := 'Misplaced quoted string'; hexVeErrNoLocalPart: Result := 'No local part specified'; hexVeErrNoDomain: Result := 'No domain specified'; hexVeErrInvalidDomain: Result := 'Invalid domain'; hexVeErrInvalidDomainLiteral: Result := 'Invalid domain literal'; hexVeErrNoDnsServerConfigured: Result := 'No DNS servers configured'; hexVeErrDomainDoesNotExist: Result := 'Domain does not exist'; hexVeErrNoMxForDomain: Result := 'No mail exchange for domain'; hexVeErrCouldNotVerifyRecipient: Result := 'Could not verify recipient'; hexVeErrRecipientRejected: Result := 'Recipient rejected'; hexVeErrNoAddrSpecified: Result := 'No address was specified'; hexVeErrMailboxFull: Result := 'Mailbox is full'; hexVeErrBogusMxRecords: Result := 'MX records do not have valid IP addresses'; hexVeErrSenderBlocked: Result := 'SMTP server is blocking email from this sender'; hexVeErrDetectedCatchAll: Result := 'SMTP server does not reject bad addresses'; else Result := GetLicenseErrorString( error ); end; end; function GetLicenseErrorString( error: Integer ) : String; begin case error of 0: Result := 'Success'; 2: Result := 'License file not found'; 3: Result := 'Could not open license file'; 4: Result := 'License file is corrupt'; 5: Result := 'License is for wrong product'; 6: Result := 'License is for wrong version'; 7: Result := 'License does not cover all processors in the machine'; else Result := Format( 'Other error: %d', [error] ); end; end; end.