Sample code for 30+ languages & platforms
Tcl

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.

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 more useful as data than as a log string. GetLastJsonData exposes that as a JsonObject you can query programmatically. Because it reflects only the most recent call, retrieve it right away: any subsequent MailMan method may replace it.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set 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.

set mailman [new_CkMailMan]

#  Configure the SMTP server connection.
CkMailMan_put_SmtpHost $mailman "smtp.example.com"
CkMailMan_put_SmtpPort $mailman 465
CkMailMan_put_SmtpSsl $mailman 1
CkMailMan_put_SmtpUsername $mailman "user@example.com"
CkMailMan_put_SmtpPassword $mailman "myPassword"

#  Send an email.
set email [new_CkEmail]

CkEmail_put_Subject $email "Test email"
CkEmail_put_From $email "alice@example.com"
CkEmail_AddTo $email "Bob" "bob@example.com"
CkEmail_put_Body $email "Hello!"
set success [CkMailMan_SendEmail $mailman $email]
if {$success == 0} then {
    puts [CkMailMan_lastErrorText $mailman]
    delete_CkMailMan $mailman
    delete_CkEmail $email
    exit
}

#  Immediately retrieve any JSON details produced by the send.
set json [new_CkJsonObject]

CkMailMan_GetLastJsonData $mailman $json
puts [CkJsonObject_emit $json]

#  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.

delete_CkMailMan $mailman
delete_CkEmail $email
delete_CkJsonObject $json