SQL Server
SQL Server
Set the Email Body from a BinData
See more Email Object Examples
Demonstrates the Chilkat Email.SetBodyBd method, which sets the main email body from the binary data in a BinData object. The second argument is the MIME Content-Type, the third is the disposition (may be empty, inline, or attachment), and the fourth is the filename. This example loads HTML content into a BinData and sets it as the body.
Background:
SetBodyBd gives low-level control over the body when you already have its bytes and want to specify the exact Content-Type and MIME disposition yourself. It suits content that is generated or stored as binary — for example an EDI payload, a pre-rendered HTML fragment, or any custom content type — where the convenience of SetHtmlBody / SetTextBody does not apply.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 SetBodyBd method, which sets the main email body from the binary data in
-- a BinData object. The second argument is the MIME Content-Type, the third is the
-- disposition (may be empty, "inline", or "attachment"), and the fourth is the filename.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @email, 'Subject', 'Body from BinData'
-- Load the body content from a file into a BinData object.
DECLARE @bd int
EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT
EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, 'qa_data/html/body.html'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @bd, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @bd
RETURN
END
-- Set the main body from the binary data as text/html.
EXEC sp_OAMethod @email, 'SetBodyBd', @success OUT, @bd, 'text/html', '', ''
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @bd
RETURN
END
EXEC sp_OAMethod @email, 'HasHtmlBody', @iTmp0 OUT
PRINT 'HasHtmlBody: ' + @iTmp0
-- Note: The path "qa_data/html/body.html" is a relative local filesystem path,
-- relative to the current working directory of the running application.
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @bd
END
GO