SQL Server
SQL Server
Get SpamAssassin Score for an Email
See more Email Object Examples
Uses Postmark’s spam API (a RESTfull interface to the SpamAssassin filter tool) to analyze an email to get a spam score.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 @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
-- First build an email to check.
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', 'this is a test'
EXEC sp_OASetProperty @email, 'From', 'support@chilkatsoft.com'
EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'John Doe', 'john@example.com'
EXEC sp_OAMethod @email, 'AddPlainTextAlternativeBody', @success OUT, 'this is a test'
EXEC sp_OAMethod @email, 'AddHtmlAlternativeBody', @success OUT, '<html><body><b>Hello John!</b><p>This is a test</p></body></html>'
EXEC sp_OAMethod @email, 'AddFileAttachment2', @success OUT, 'qa_data/jpg/starfish.jpg', 'image/jpeg'
-- Check this email by implementing this curl command:
-- curl -X POST "https://spamcheck.postmarkapp.com/filter"
-- -H "Accept: application/json"
-- -H "Content-Type: application/json"
-- -v
-- -d '{"email":"raw dump of email", "options":"short"}'
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @email, 'GetMime', @sTmp0 OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'email', @sTmp0
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'options', 'short'
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
DECLARE @resp int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT
EXEC sp_OAMethod @http, 'HttpJson', @success OUT, 'POST', 'https://spamcheck.postmarkapp.com/filter', @json, 'application/json', @resp
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT 'response status code = ' + @iTmp0
PRINT 'response body: '
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
END
GO