SQL Server
SQL Server
Set a MIME Body from HTML
See more MIME Examples
Demonstrates the Chilkat Mime.SetBodyFromHtml method, which sets the body as HTML and changes the media type to text/html. The only argument is the HTML text.
Background: Setting an HTML body is how you produce the rich-formatted part of a message. Chilkat marks it
text/html and chooses the encoding based on the content — 7bit for ASCII, a charset-aware encoding otherwise. In practice an HTML email is usually paired with a plain-text alternative inside a multipart/alternative so clients that cannot render HTML still have readable text.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 Mime.SetBodyFromHtml method, which sets the body as HTML and changes the media
-- type to text/html. The only argument is the HTML text.
DECLARE @mime int
EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @html nvarchar(4000)
SELECT @html = '<html><body><h1>Hello</h1><p>This is an HTML body.</p></body></html>'
EXEC sp_OAMethod @mime, 'SetBodyFromHtml', @success OUT, @html
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mime
RETURN
END
EXEC sp_OAGetProperty @mime, 'ContentType', @sTmp0 OUT
PRINT 'Content-Type: ' + @sTmp0
EXEC @hr = sp_OADestroy @mime
END
GO