SQL Server Requires Chilkat v11.0.0+
SQL Server
Create, save, and reopen a plain-text email
See more Email Object Examples
Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.
Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
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, 'From', 'Sam Lee <sam@example.com>'
EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Alex Rivera', 'alex@example.net'
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
RETURN
END
EXEC sp_OASetProperty @email, 'Subject', 'Hello'
EXEC sp_OASetProperty @email, 'Body', 'This is a plain-text message.'
EXEC sp_OAMethod @email, 'SaveEml', @success OUT, 'message.eml'
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
RETURN
END
DECLARE @received int
EXEC @hr = sp_OACreate 'Chilkat.Email', @received OUT
EXEC sp_OAMethod @received, 'LoadEml', @success OUT, 'message.eml'
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @received, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @received
RETURN
END
EXEC sp_OAGetProperty @received, 'From', @sTmp0 OUT
PRINT @sTmp0
EXEC sp_OAGetProperty @received, 'Subject', @sTmp0 OUT
PRINT @sTmp0
EXEC sp_OAMethod @received, 'GetPlainTextBody', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @received
END
GO