SQL Server
SQL Server
Fetch a POP3 Message's Raw MIME by UIDL
See more POP3 Examples
Demonstrates the Chilkat MailMan.FetchMimeBd method, which fetches an email from the POP3 server by UIDL and stores the raw MIME source bytes in a BinData. Chilkat clears the BinData before downloading. This example fetches one message's MIME into a BinData.
Background: Sometimes you want the message exactly as it arrived — the raw MIME bytes — rather than a parsed
Email object, for example to archive it verbatim as a .eml file, forward it untouched, or hash it. Fetching into a BinData preserves every byte precisely, without any parsing or re-encoding that could alter the original.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the MailMan.FetchMimeBd method, which fetches an email from the POP3 server
-- by UIDL and stores the raw MIME source bytes in a BinData. Chilkat clears the BinData
-- before downloading.
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'
-- Fetch the raw MIME of a specific message by UIDL into a BinData.
DECLARE @bdMime int
EXEC @hr = sp_OACreate 'Chilkat.BinData', @bdMime OUT
EXEC sp_OAMethod @mailman, 'FetchMimeBd', @success OUT, '0000000123abcdef', @bdMime
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mailman
EXEC @hr = sp_OADestroy @bdMime
RETURN
END
EXEC sp_OAGetProperty @bdMime, 'NumBytes', @iTmp0 OUT
PRINT 'MIME size (bytes) = ' + @iTmp0
-- 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 @bdMime
END
GO