SQL Server
SQL Server
Get Delivery-Status Info as JSON
See more Email Object Examples
Demonstrates the Chilkat Email.GetDsnInfo method, which — when IsMultipartReport indicates the email is a multipart/report — obtains the delivery-status information as a JsonObject. This example loads a bounce message, confirms it is a report, and prints the extracted DSN details as JSON.
Background: A bounce (DSN) carries its key facts — which recipient failed, the status code, the reporting server — in a machine-readable
message/delivery-status part. Rather than parsing those raw fields yourself, GetDsnInfo gathers them into a structured JSON document you can query with the JsonObject API, making it easy to automate bounce handling and prune failed addresses from a mailing list.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 GetDsnInfo method, which, for a multipart/report email, obtains the
-- delivery-status information as a JSON object.
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_OAMethod @email, 'LoadEml', @success OUT, 'qa_data/eml/dsn_bounce.eml'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
RETURN
END
-- Only meaningful for a multipart/report email.
EXEC sp_OAMethod @email, 'IsMultipartReport', @iTmp0 OUT
IF @iTmp0 = 1
BEGIN
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @email, 'GetDsnInfo', @success OUT, @json
IF @success = 1
BEGIN
EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
PRINT @sTmp0
END
END
ELSE
BEGIN
PRINT 'This email is not a multipart/report.'
END
-- Note: The path "qa_data/..." is a relative local filesystem path,
-- relative to the current working directory of the running application.
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @json
END
GO