SQL Server
SQL Server
Fetch the UIDLs of All POP3 Messages
See more POP3 Examples
Demonstrates the Chilkat MailMan.FetchUidls method, which retrieves the UIDLs of the messages currently in the POP3 mailbox and stores them in a StringTable, one entry per message, in the server's current mailbox order. This example lists every UIDL.
Background: The UIDL list is the starting point for incremental mail retrieval. A client keeps a record of the UIDLs it has already downloaded; on each check it fetches the current list, computes the difference, and downloads only the new ones (see
FetchUidlSet). This is how "leave a copy on the server" works without repeatedly re-downloading the same messages.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.FetchUidls method, which retrieves the UIDLs of the messages
-- currently in the POP3 mailbox and stores them in a StringTable, one entry per message, in
-- the server's current mailbox order.
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'
-- Retrieve the UIDLs of all messages in the mailbox.
DECLARE @uidls int
EXEC @hr = sp_OACreate 'Chilkat.StringTable', @uidls OUT
EXEC sp_OAMethod @mailman, 'FetchUidls', @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
DECLARE @n int
EXEC sp_OAGetProperty @uidls, 'Count', @n OUT
PRINT 'Mailbox contains ' + @n + ' messages.'
DECLARE @i int
SELECT @i = 0
WHILE @i <= @n - 1
BEGIN
EXEC sp_OAMethod @uidls, 'StringAt', @sTmp0 OUT, @i
PRINT 'UIDL ' + @i + ': ' + @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 @uidls
END
GO