SQL Server
SQL Server
Send a Raw IMAP Command (Binary)
See more IMAP Examples
Demonstrates the Chilkat Imap.RawCommandBd method, which sends raw IMAP command bytes and receives the raw response bytes. The first argument is a BinData holding the command — without an IMAP tag or trailing CRLF, which Chilkat supplies — and the second is a BinData that receives the response.
Background: This is an escape hatch for rare server extensions the API does not otherwise expose. It is intended for commands with a single-line response that do not change
Imap object state such as the selected mailbox or message count. For everyday operations, use the dedicated methods, which parse responses and maintain object state for you.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the Imap.RawCommandBd method, which sends raw IMAP command bytes and receives
-- the raw response bytes. The 1st argument is a BinData containing the command (without a tag
-- or trailing CRLF -- Chilkat supplies both), and the 2nd is a BinData that receives the
-- response.
DECLARE @imap int
EXEC @hr = sp_OACreate 'Chilkat.Imap', @imap OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @imap, 'Ssl', 1
EXEC sp_OASetProperty @imap, 'Port', 993
EXEC sp_OAMethod @imap, 'Connect', @success OUT, 'imap.example.com'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @imap
RETURN
END
EXEC sp_OAMethod @imap, 'Login', @success OUT, 'user@example.com', 'myPassword'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @imap
RETURN
END
-- Build the raw command. Do not include an IMAP tag or a trailing CRLF.
DECLARE @bdCmd int
EXEC @hr = sp_OACreate 'Chilkat.BinData', @bdCmd OUT
EXEC sp_OAMethod @bdCmd, 'AppendString', @success OUT, 'CAPABILITY', 'utf-8'
DECLARE @bdResp int
EXEC @hr = sp_OACreate 'Chilkat.BinData', @bdResp OUT
EXEC sp_OAMethod @imap, 'RawCommandBd', @success OUT, @bdCmd, @bdResp
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @imap
EXEC @hr = sp_OADestroy @bdCmd
EXEC @hr = sp_OADestroy @bdResp
RETURN
END
-- Interpret the response bytes as a UTF-8 string.
DECLARE @respStr nvarchar(4000)
EXEC sp_OAMethod @bdResp, 'GetString', @respStr OUT, 'utf-8'
PRINT @respStr
EXEC sp_OAMethod @imap, 'Disconnect', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @imap
EXEC @hr = sp_OADestroy @bdCmd
EXEC @hr = sp_OADestroy @bdResp
RETURN
END
EXEC @hr = sp_OADestroy @imap
EXEC @hr = sp_OADestroy @bdCmd
EXEC @hr = sp_OADestroy @bdResp
END
GO