PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkEmail.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the GetDsnInfo method, which, for a multipart/report email, obtains the
; delivery-status information as a JSON object.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkEmail::ckLoadEml(email,"qa_data/eml/dsn_bounce.eml")
If success = 0
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
; Only meaningful for a multipart/report email.
If CkEmail::ckIsMultipartReport(email) = 1
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkEmail::ckGetDsnInfo(email,json)
If success = 1
Debug CkJsonObject::ckEmit(json)
EndIf
Else
Debug "This email is not a multipart/report."
EndIf
; Note: The path "qa_data/..." is a relative local filesystem path,
; relative to the current working directory of the running application.
CkEmail::ckDispose(email)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure