Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Verify Email Addresses with VerifyRecipients
Verify email recipients. This example demonstrates the usage of the VerifyRecipients method. Please see this blog post for more information VerifyRecipients -- Validating Email Addresses uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, CHILKATMAILLib2_TLB, CHILKATUTILLib_TLB, OleCtrls; ... procedure TForm1.Button1Click(Sender: TObject); var mailman: TChilkatMailMan2; success: Integer; email: CHILKATMAILLib2_TLB.IChilkatEmail2; saBadAddrs: CHILKATUTILLib_TLB.ICkStringArray; i: Integer; n: Integer; begin // The mailman object is used for sending and receiving email. mailman := TChilkatMailMan2.Create(Self); // Any string argument automatically begins the 30-day trial. success := mailman.UnlockComponent('30-day trial'); if (success <> 1) then begin ShowMessage('Component unlock failed'); end; // Set the SMTP server. // This code was tested against both mail.chilkatsoft.com // and smtp.comcast.net // mailman.SmtpHost = "mail.chilkatsoft.com"; // mailman.SmtpUsername = "admin@chilkatsoft.com"; // mailman.SmtpPassword = "****"; mailman.SmtpHost := 'smtp.comcast.net'; // Create an email object. // We'll never actually send this email. It's only used // to test the recipients. email := CoChilkatEmail2.Create(); email.Subject := 'This is a test'; email.Body := 'This is a test'; email.From := 'Chilkat Support <support@chilkatsoft.com>'; // Add recipients to be checked. // (When this was tested, a_real_person was replaced with // a valid email address.) email.AddTo('A Real Person','a_real_person@comcast.net'); email.AddTo('Testing','doesNotExist7434@comcast.net'); email.AddTo('Admin','admin@chilkatsoft.com'); email.AddTo('Not Exist','doesNotExist@chilkatsoft.com'); email.AddCC('Not Exist','DoesNotExist7213@gmail.com'); email.AddBcc('Exists','chilkat.support@gmail.com'); // NOTE: A mail server can only verify the email addresses // specific to it's domain. Therefore, when using smtp.comcast.net, // only comcast.net email addresses will be flagged as invalid, // and when using mail.chilkatsoft.com, only chilkatsoft.com // email addresses are flagged as invalid. // Return all bad email addresses in saBadAddrs: saBadAddrs := mailman.VerifyRecipients(email) as CHILKATUTILLib_TLB.ICkStringArray; if (saBadAddrs = nil ) then begin ShowMessage(mailman.LastErrorText); end else begin // List the invalid email addresses: if (saBadAddrs.Count > 0) then begin n := saBadAddrs.Count; for i := 0 to n - 1 do begin Memo1.Lines.Add(saBadAddrs.GetString(i)); end; // Examine the SMTP session log to see how the email // addresses were caught: ShowMessage(mailman.SmtpSessionLog); end; end; end; |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.