Sample code for 30+ languages & platforms
SQL Server

Verify Connectivity to the SMTP Server

See more SMTP Examples

Demonstrates the Chilkat MailMan.VerifySmtpConnection method, which tests whether a TCP/IP connection can be established with the configured SMTP server. It verifies connectivity only — it does not authenticate. This example configures the SMTP host and checks whether it can be reached.

Background: When a send fails, it helps to know where it broke. VerifySmtpConnection isolates the first hop — can the client even reach the server on the configured host and port, and complete the TLS handshake? A failure here points at networking, firewall, DNS, port, or certificate issues rather than credentials. Once connectivity is confirmed, VerifySmtpLogin tests the authentication step.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    --  Demonstrates the MailMan.VerifySmtpConnection method, which tests whether a TCP/IP
    --  connection can be established with the configured SMTP server.  It verifies connectivity
    --  only (it does not authenticate).

    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

    --  Test connectivity to the SMTP server.
    DECLARE @connected int
    EXEC sp_OAMethod @mailman, 'VerifySmtpConnection', @connected OUT

    IF @connected = 1
      BEGIN

        PRINT 'Successfully connected to the SMTP server.'
      END
    ELSE
      BEGIN

        PRINT 'Could not connect to the SMTP server.'
      END

    EXEC @hr = sp_OADestroy @mailman


END
GO