PowerBuilder
PowerBuilder
Get JSON Details from the Last MailMan Call
See more SMTP Examples
Demonstrates the Chilkat MailMan.GetLastJsonData method, which copies any structured JSON details produced by the immediately preceding method call into a JsonObject. Not every MailMan method produces JSON details, and the method must be called immediately after the call of interest. This example sends an email and then retrieves the JSON details, which include the negotiated TLS version and parameters, the SMTP server's last response and status code, and the result of SMTP authentication.
Tip: JSON parsing code for this result can be generated at Chilkat Tools.
Background: Some Chilkat methods gather structured diagnostic information alongside their normal result — details that are far more useful as data than as a log string.
GetLastJsonData exposes that as a JsonObject you can query programmatically, making it easy to record exactly which TLS version was negotiated or which SMTP status code came back. Because it reflects only the most recent call, retrieve it right away: any subsequent MailMan method may replace it.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Email
oleobject loo_Json
li_Success = 0
// Demonstrates the MailMan.GetLastJsonData method, which copies any structured JSON details
// produced by the immediately preceding method call into a JsonObject. Not every MailMan
// method produces JSON details, and it must be called immediately after the method of
// interest.
loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
destroy loo_Mailman
MessageBox("Error","Connecting to COM object failed")
return
end if
// Configure the SMTP server connection.
loo_Mailman.SmtpHost = "smtp.example.com"
loo_Mailman.SmtpPort = 465
loo_Mailman.SmtpSsl = 1
loo_Mailman.SmtpUsername = "user@example.com"
loo_Mailman.SmtpPassword = "myPassword"
// Send an email.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
loo_Email.Subject = "Test email"
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
loo_Email.Body = "Hello!"
li_Success = loo_Mailman.SendEmail(loo_Email)
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
destroy loo_Email
return
end if
// Immediately retrieve any JSON details produced by the send.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Mailman.GetLastJsonData(loo_Json)
// Emit non-compact (indented) JSON for readability.
loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()
// Sample output:
//
// {
// "tls": {
// "params": {
// "sniHostname": "mail.chilkat.io",
// "allowConnectionOnlyIfServerChooses": "SSL 3.0 or higher"
// },
// "negotiatedTlsVersion": "TLS 1.3"
// },
// "smtp": {
// "lastResponse": "250 OK id=1wkjeT-00000002yb4-0uve",
// "lastStatus": 250
// },
// "smtpAuth": {
// "user": "test@chilkat.io",
// "method": "login",
// "statusCode": 235,
// "success": true
// }
// }
//
// JSON parsing code for this result can be generated at Chilkat's online tool:
// https://tools.chilkat.io/jsonParse
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.
destroy loo_Mailman
destroy loo_Email
destroy loo_Json