Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Verify Email Addresses with VerifyRecipientsVerify email recipients. This example demonstrates the usage of the VerifyRecipients method. Please see this blog post for more information VerifyRecipients -- Validating Email Addresses
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) -- The mailman object is used for sending and receiving email. DECLARE @mailman int EXEC @hr = sp_OACreate 'Chilkat.MailMan2', @mailman OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Any string argument automatically begins the 30-day trial. DECLARE @success int EXEC sp_OAMethod @mailman, 'UnlockComponent', @success OUT, '30-day trial' IF @success <> 1 BEGIN PRINT 'Component unlock failed' RETURN 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 = "****"; EXEC sp_OASetProperty @mailman, 'SmtpHost', 'smtp.comcast.net' -- Create an email object. -- We'll never actually send this email. It's only used -- to test the recipients. DECLARE @email int EXEC @hr = sp_OACreate 'Chilkat.Email2', @email OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OASetProperty @email, 'Subject', 'This is a test' EXEC sp_OASetProperty @email, 'Body', 'This is a test' EXEC sp_OASetProperty @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.) EXEC sp_OAMethod @email, 'AddTo', NULL, 'A Real Person', 'a_real_person@comcast.net' EXEC sp_OAMethod @email, 'AddTo', NULL, 'Testing', 'doesNotExist7434@comcast.net' EXEC sp_OAMethod @email, 'AddTo', NULL, 'Admin', 'admin@chilkatsoft.com' EXEC sp_OAMethod @email, 'AddTo', NULL, 'Not Exist', 'doesNotExist@chilkatsoft.com' EXEC sp_OAMethod @email, 'AddCC', NULL, 'Not Exist', 'DoesNotExist7213@gmail.com' EXEC sp_OAMethod @email, 'AddBcc', NULL, '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: DECLARE @saBadAddrs int EXEC sp_OAMethod @mailman, 'VerifyRecipients', @saBadAddrs OUT, @email IF @saBadAddrs Is NULL BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END ELSE BEGIN -- List the invalid email addresses: EXEC sp_OAGetProperty @saBadAddrs, 'Count', @sTmp0 OUT IF @sTmp0 > 0 BEGIN DECLARE @i int DECLARE @n int EXEC sp_OAGetProperty @saBadAddrs, 'Count', @n OUT SELECT @i = 0 WHILE @i <= @n - 1 BEGIN EXEC sp_OAMethod @saBadAddrs, 'GetString', @sTmp0 OUT, @i PRINT @sTmp0 SELECT @i = @i + 1 END -- Examine the SMTP session log to see how the email -- addresses were caught: EXEC sp_OAGetProperty @mailman, 'SmtpSessionLog', @sTmp0 OUT PRINT @sTmp0 END END END GO |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.