Sample code for 30+ languages & platforms
SQL Server

Delete a Set of POP3 Messages by UIDL

See more POP3 Examples

Demonstrates the Chilkat MailMan.DeleteUidlSet method, which marks the POP3 messages whose UIDLs are listed in a StringTable for deletion. Chilkat processes the UIDL set and sends a DELE command for each located message. This example deletes two messages by UIDL.

Background: When you already know exactly which messages to remove — by their stable UIDLs — DeleteUidlSet deletes them all in one call without first downloading them. It is the efficient counterpart to fetching-then-deleting: for example, after processing messages elsewhere, hand back just their UIDLs to clear them. The deletions are committed when the POP3 session ends (unless ImmediateDelete is set).

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.DeleteUidlSet method, which marks the POP3 messages whose UIDLs
    --  are listed in a StringTable for deletion.  Chilkat sends DELE for each located message.

    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 POP3 server connection.
    EXEC sp_OASetProperty @mailman, 'MailHost', 'pop.example.com'
    EXEC sp_OASetProperty @mailman, 'MailPort', 995
    EXEC sp_OASetProperty @mailman, 'PopSsl', 1
    EXEC sp_OASetProperty @mailman, 'PopUsername', 'user@example.com'
    EXEC sp_OASetProperty @mailman, 'PopPassword', 'myPassword'

    --  Build the set of UIDLs to delete.
    DECLARE @uidls int
    EXEC @hr = sp_OACreate 'Chilkat.StringTable', @uidls OUT

    EXEC sp_OAMethod @uidls, 'Append', @success OUT, '0000000123abcdef'
    EXEC sp_OAMethod @uidls, 'Append', @success OUT, '0000000124abcdef'

    --  Mark the messages for deletion.

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

    --  Unless the ImmediateDelete property is set to 1, the messages are only marked for
    --  deletion.  End the POP3 session (which sends the QUIT command) to commit the deletions.
    EXEC sp_OAMethod @mailman, 'Pop3EndSession', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mailman
        EXEC @hr = sp_OADestroy @uidls
        RETURN
      END


    PRINT 'Deleted the UIDL set from the POP3 server.'

    --  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 @uidls


END
GO