SQL Server
SQL Server
Verify Email Recipients Without Sending
See more SMTP Examples
Demonstrates the Chilkat MailMan.VerifyRecips method, which begins the SMTP send process for an email, sends the recipient addresses to the SMTP server, and then aborts before sending the message content. Recipient addresses rejected by the server are returned in the StringArray. This example checks two recipients and lists any that were rejected.
Background: During an SMTP transaction each recipient is offered with a
RCPT TO command, and the server accepts or rejects it before any message content is transferred. VerifyRecips exploits that: it runs the transaction just far enough to collect those verdicts, then aborts — letting you validate an address list without actually delivering mail. Note that many servers accept everything at this stage and bounce later, so a clean result is not a guarantee of deliverability.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the MailMan.VerifyRecips method, which begins the SMTP send process for an
-- email, sends the recipient addresses to the SMTP server, and then aborts before sending
-- the message content. Recipient addresses rejected by the server are returned in the
-- StringArray.
DECLARE @mailman int
EXEC @hr = sp_OACreate 'Chilkat.MailMan', @mailman OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Configure the SMTP server connection.
EXEC sp_OASetProperty @mailman, 'SmtpHost', 'smtp.example.com'
EXEC sp_OASetProperty @mailman, 'SmtpPort', 465
EXEC sp_OASetProperty @mailman, 'SmtpSsl', 1
EXEC sp_OASetProperty @mailman, 'SmtpUsername', 'user@example.com'
EXEC sp_OASetProperty @mailman, 'SmtpPassword', 'myPassword'
-- Build an email with the recipients to verify.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
EXEC sp_OASetProperty @email, 'Subject', 'Recipient check'
EXEC sp_OASetProperty @email, 'From', 'alice@example.com'
EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Bob', 'bob@example.com'
EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Nobody', 'nobody@example.com'
-- Ask the server which recipients it will accept. Rejected addresses are returned.
DECLARE @badAddrs int
EXEC @hr = sp_OACreate 'Chilkat.StringArray', @badAddrs OUT
EXEC sp_OAMethod @mailman, 'VerifyRecips', @success OUT, @email, @badAddrs
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mailman
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @badAddrs
RETURN
END
DECLARE @n int
EXEC sp_OAGetProperty @badAddrs, 'Count', @n OUT
PRINT 'Rejected recipients: ' + @n
DECLARE @i int
SELECT @i = 0
WHILE @i <= @n - 1
BEGIN
EXEC sp_OAMethod @badAddrs, 'GetString', @sTmp0 OUT, @i
PRINT @sTmp0
SELECT @i = @i + 1
END
-- Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
-- connects and authenticates -- using the property settings above -- whenever a server
-- operation requires it. Calling the explicit connect/authenticate methods can still be
-- helpful to determine whether a failure occurs while connecting or while authenticating.
EXEC @hr = sp_OADestroy @mailman
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @badAddrs
END
GO