Sample code for 30+ languages & platforms
SQL Server

Send an SMTP RSET Command

See more SMTP Examples

Demonstrates the Chilkat MailMan.SmtpReset method, which sends an SMTP RSET command to the server. RSET resets the server-side state of the current mail transaction. This example opens a connection, sends RSET, and closes.

Background: During an SMTP session a message is built up across MAIL FROM and RCPT TO commands. If you need to abandon that partially-specified transaction — say an error occurred midway — RSET clears it without dropping the connection, so the same authenticated session can start a fresh message. It's a lightweight way to recover in-session rather than reconnecting.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  Demonstrates the MailMan.SmtpReset method, which sends an SMTP RSET command to the server.
    --  RSET resets the server-side state of the current mail transaction.

    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'

    --  Open the connection.

    EXEC sp_OAMethod @mailman, 'OpenSmtpConnection', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mailman
        RETURN
      END

    --  Reset the current SMTP mail transaction.
    EXEC sp_OAMethod @mailman, 'SmtpReset', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mailman
        RETURN
      END

    EXEC sp_OAMethod @mailman, 'CloseSmtpConnection', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mailman
        RETURN
      END


    PRINT 'Sent SMTP RSET.'

    EXEC @hr = sp_OADestroy @mailman


END
GO