SQL Server
SQL Server
Convert Inline Data-URL Images to Related Parts
See more Email Object Examples
Demonstrates the Chilkat Email.ConvertInlineImages method, which converts images embedded inline within HTML (as base64 data URLs) into multipart/related MIME parts referenced from the HTML by cid:. This example sets an HTML body containing a data-URL image and converts it.
Background: HTML can embed an image two ways: as a
data: URL (the base64 bytes sit right in the src attribute) or as a related part referenced by cid:. Many email clients don't render data: URLs for security reasons, so converting them to proper multipart/related parts — the traditional email way to embed images — greatly improves how reliably the images display.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 ConvertInlineImages method, which converts images embedded inline within
-- HTML (as base64 data URLs) into multipart/related MIME parts referenced from the HTML by
-- CID.
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', 'Convert inline images'
-- An HTML body with a base64 data-URL image (a 1x1 PNG).
EXEC sp_OAMethod @email, 'SetHtmlBody', NULL, '<html><body><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="/></body></html>'
EXEC sp_OAGetProperty @email, 'NumRelatedItems', @iTmp0 OUT
PRINT 'NumRelatedItems before = ' + @iTmp0
-- Convert the inline data-URL image(s) to multipart/related parts referenced by CID.
EXEC sp_OAMethod @email, 'ConvertInlineImages', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
RETURN
END
EXEC sp_OAGetProperty @email, 'NumRelatedItems', @iTmp0 OUT
PRINT 'NumRelatedItems after = ' + @iTmp0
EXEC @hr = sp_OADestroy @email
END
GO