SQL Server
SQL Server
Verify SMTP Login (Connect and Authenticate)
See more SMTP Examples
Demonstrates the Chilkat MailMan.VerifySmtpLogin method, which tests whether Chilkat can connect to the configured SMTP server and successfully authenticate using the current SMTP authentication settings. This example configures the SMTP host and credentials and verifies login.
Background: This goes one step further than
VerifySmtpConnection: after reaching the server it also performs the AUTH exchange with your username and password (or OAuth2 token). It's the ideal preflight check when validating credentials or diagnosing "why won't my mail send?" — a false result after a good connection points squarely at bad credentials or an unsupported auth method rather than a network problem.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @success int
SELECT @success = 0
-- Demonstrates the MailMan.VerifySmtpLogin method, which tests whether Chilkat can connect
-- to the configured SMTP server and successfully authenticate using the current SMTP
-- authentication settings.
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'
-- Test both connectivity and authentication.
DECLARE @loggedIn int
EXEC sp_OAMethod @mailman, 'VerifySmtpLogin', @loggedIn OUT
IF @loggedIn = 1
BEGIN
PRINT 'Successfully connected and authenticated with the SMTP server.'
END
ELSE
BEGIN
PRINT 'SMTP connect or login failed.'
END
EXEC @hr = sp_OADestroy @mailman
END
GO