Sample code for 30+ languages & platforms
SQL Server

Get POP3 Mailbox Info as XML

See more POP3 Examples

Demonstrates the Chilkat MailMan.GetMailboxInfoXml method, which returns an XML document describing the messages currently in the POP3 mailbox — including each message's UIDL and size in bytes. This example configures the POP3 connection and prints the listing.

Tip: XML parsing code for this result can be generated at Chilkat Tools.

Background: Before downloading, it is often useful to survey what's in the mailbox. This method combines POP3's UIDL listing (a stable unique ID per message) with LIST sizes into one XML result. With it you can decide which messages to fetch or delete by UIDL — for example skipping ones already processed, or targeting only messages above a certain size.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    --  Demonstrates the MailMan.GetMailboxInfoXml method, which returns an XML document with
    --  information about the messages currently in the POP3 mailbox, including the UIDL and size
    --  (in bytes) of each 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'

    --  Retrieve the mailbox listing as XML.
    DECLARE @xmlInfo nvarchar(4000)
    EXEC sp_OAMethod @mailman, 'GetMailboxInfoXml', @xmlInfo OUT

    PRINT @xmlInfo

    --  The returned XML looks similar to:
    --  
    --    <mailbox count="2" size="4786">
    --        <email uidl="UID22-1784216315" msgNum="1" size="2394" />
    --        <email uidl="UID23-1784216315" msgNum="2" size="2392" />
    --    </mailbox>
    --  
    --  XML parsing code for this result can be generated at Chilkat's online tool:
    --  https://tools.chilkat.io/xmlParse

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


END
GO