SQL Server Requires Chilkat v11.0.0+
SQL Server
Request a SpamAssassin score for a sample email
See more Email Object Examples
Submit a synthetic message to Postmark’s SpamCheck endpoint. The service receives the complete MIME you provide. Request a short result and check both the HTTP status and the API success field before reading the numeric score. SpamCheck API documentation.
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
-- 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', 'Workshop team <events@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', 'Workshop registration'
EXEC sp_OASetProperty @email, 'Body', 'Your workshop registration is confirmed.'
DECLARE @request int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @request OUT
EXEC sp_OAMethod @email, 'GetMime', @sTmp0 OUT
EXEC sp_OAMethod @request, 'UpdateString', @success OUT, 'email', @sTmp0
EXEC sp_OAMethod @request, 'UpdateString', @success OUT, 'options', 'short'
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
EXEC sp_OASetProperty @http, 'RequireSslCertVerify', 1
DECLARE @resp int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT
EXEC sp_OAMethod @http, 'HttpJson', @success OUT, 'POST', 'https://spamcheck.postmarkapp.com/filter', @request, 'application/json', @resp
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
IF (@success <> 1) or (@iTmp0 <> 200)
BEGIN
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT 'SpamCheck request failed. HTTP ' + @iTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @request
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
RETURN
END
DECLARE @result int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @result OUT
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
EXEC sp_OAMethod @result, 'Load', @success OUT, @sTmp0
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @result, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @request
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @result
RETURN
END
EXEC sp_OAMethod @result, 'BoolOf', @iTmp0 OUT, 'success'
IF @iTmp0 <> 1
BEGIN
EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'message'
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @request
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @result
RETURN
END
EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'score'
PRINT 'SpamAssassin score: ' + @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @request
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @result
END
GO