Sample code for 30+ languages & platforms
SQL Server

Load Emails from a .mbx Mailbox File

See more POP3 Examples

Demonstrates the Chilkat MailMan.LoadMbxFile method, which loads emails from a .mbx mailbox file and stores them in an EmailBundle. If a filter has been configured, only the matching emails are returned. This example loads a local mailbox file and iterates the resulting bundle.

Background: An .mbx file is a single-file mailbox format that stores many messages concatenated together — historically produced by Outlook Express and similar clients. LoadMbxFile parses that archive into individual Email objects, which is useful for importing, migrating, or analyzing old mail without any server connection. No POP3 or SMTP session is involved — this reads purely from disk.

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.LoadMbxFile method, which loads emails from a .mbx mailbox file
    --  and stores them in an EmailBundle.  If a filter has been configured, only the matching
    --  emails are returned.

    DECLARE @mailman int
    EXEC @hr = sp_OACreate 'Chilkat.MailMan', @mailman OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  Load emails from a local .mbx mailbox file (no server connection is made).
    DECLARE @bundle int
    EXEC @hr = sp_OACreate 'Chilkat.EmailBundle', @bundle OUT

    EXEC sp_OAMethod @mailman, 'LoadMbxFile', @success OUT, 'qa_data/mbx/inbox.mbx', @bundle
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mailman
        EXEC @hr = sp_OADestroy @bundle
        RETURN
      END

    DECLARE @n int
    EXEC sp_OAGetProperty @bundle, 'MessageCount', @n OUT


    PRINT 'Loaded ' + @n + ' emails from the .mbx file.'

    DECLARE @email int
    EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT

    DECLARE @i int

    SELECT @i = 0
    WHILE @i <= @n - 1
      BEGIN
        EXEC sp_OAMethod @bundle, 'EmailAt', @success OUT, @i, @email
        EXEC sp_OAGetProperty @email, 'Subject', @sTmp0 OUT
        PRINT @sTmp0
        SELECT @i = @i + 1
      END

    --  Note: The path "qa_data/mbx/inbox.mbx" is a relative local filesystem path,
    --  relative to the current working directory of the running application.

    EXEC @hr = sp_OADestroy @mailman
    EXEC @hr = sp_OADestroy @bundle
    EXEC @hr = sp_OADestroy @email


END
GO