PowerBuilder
PowerBuilder
SMTP Inspection
See more SMTP Examples
Examine an SMTP session to view all communications sent to the SMTP server.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Email
string ls_MimeStr
li_Success = 0
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
loo_Mailman.SmtpHost = "smtp.example.com"
loo_Mailman.SmtpUsername = "myUsername"
loo_Mailman.SmtpPassword = "myPassword"
loo_Mailman.SmtpPort = 465
loo_Mailman.StartTLS = 1
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
loo_Email.Subject = "This is a test"
loo_Email.Body = "This is a test"
loo_Email.From = "Alex <alex@example.com>"
loo_Email.AddTo("Christoph","christoph@example2.com")
loo_Email.AddBcc("Victor","victor@example3.com")
// Generate the MIME that is sent when SendEmail is called
ls_MimeStr = loo_Mailman.RenderToMime(loo_Email)
Write-Debug ls_MimeStr
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
li_Success = loo_Mailman.CloseSmtpConnection()
if li_Success <> 1 then
Write-Debug "Connection to SMTP server not closed cleanly."
end if
// Examine the SMTP session log.
Write-Debug "----"
Write-Debug "Smtp Session Log:"
Write-Debug loo_Mailman.SmtpSessionLog
// ---------------------------------------------------
// Sample output:
// ---------------------------------------------------
// MIME-Version: 1.0
// Date: Fri, 06 Mar 2026 16:21:00 -0600
// Message-ID: <A5DC25990C93EC2676F4FBB2BB3BFA9EB34FF9D3@CHILKAT25>
// Content-Type: text/plain; charset=us-ascii; format=flowed
// Content-Transfer-Encoding: 7bit
// X-Priority: 3 (Normal)
// Subject: This is a test
// From: Alex <alex@example.com>
// To: Christoph <christoph@example2.com>
// Bcc: Victor <victor@example3.com>
//
// This is a test
// ----
// Smtp Session Log:
// 220 smtp.example.com ESMTP Amazon WorkMail SMTP Service
// EHLO MYCOMPUTER<CRLF>
// 250-smtp.example.com
// 250-8BITMIME
// 250-AUTH PLAIN LOGIN
// 250 Ok
// AUTH LOGIN<CRLF>
// 334 VXNlcm5hbWU6
// YWRtaW5AY2hpbGthdHNvZnQuY29t<CRLF>
// 334 UGFzc3dvcmQ6
// {PasswordOrCredentials}
// 235 Authentication successful.
// MAIL FROM:<alex@example.com><CRLF>
// 250 Ok
// RCPT TO:<christoph@example2.com><CRLF>
// 250 Ok
// RCPT TO:<victor@example3.com><CRLF>
// 250 Ok
// DATA<CRLF>
// 354 End data with <CR><LF>.<CR><LF>
// {388 bytes} <--- The MIME source of the email (examined via RenderToMime) was sent here.
// <CRLF>.<CRLF>
// 250 Ok
// QUIT<CRLF>
// 221 Bye
destroy loo_Mailman
destroy loo_Email