Sample code for 30+ languages & platforms
SQL Server

Check Whether an Email Is a multipart/report

See more Email Object Examples

Demonstrates the Chilkat Email.IsMultipartReport method, which returns true when the top-level message structure is a multipart/report (such as a bounce/DSN or a read receipt/MDN). This example loads an email and reports whether it is a multipart/report.

Background: Automated mail — delivery failures and read receipts — arrives wrapped in the multipart/report structure, which carries machine-readable report parts. Detecting it with IsMultipartReport is the first step in a bounce-handling pipeline: once you know a message is a report, you can pull its parts with GetReport or read delivery fields with GetDeliveryStatusInfo to act on failures automatically.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  Demonstrates the IsMultipartReport method, which returns true if the top-level message
    --  structure is a multipart/report (such as a bounce / DSN or a read receipt / MDN).

    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

    EXEC sp_OAMethod @email, 'IsMultipartReport', @iTmp0 OUT
    IF @iTmp0 = 1
      BEGIN

        PRINT 'This email is a multipart/report (e.g. a bounce or read receipt).'
      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


END
GO