PowerBuilder
PowerBuilder
Send a Raw SMTP Command
See more SMTP Examples
Demonstrates the Chilkat MailMan.SmtpSendRawCommand method, which sends a raw command to the SMTP server and returns the server's response. The second argument specifies the charset to use if the command contains non-US-ASCII characters, and the third indicates whether to base64-encode the command before sending. This example sends a raw NOOP on an open connection.
Background: SMTP is a line-based text protocol (
EHLO, MAIL FROM, RCPT TO, DATA, QUIT), so a raw-command hook lets you issue anything Chilkat doesn't wrap — a server extension, or a custom step during a manual auth exchange. The base64 flag exists because some SMTP exchanges (notably AUTH challenge/response) require the argument to be base64-encoded on the wire.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
string ls_Response
li_Success = 0
// Demonstrates the MailMan.SmtpSendRawCommand method, which sends a raw command to the SMTP
// server and returns the server's response. The 2nd argument is the charset used if the
// command contains non-US-ASCII characters, and the 3rd indicates whether to base64-encode
// the command before sending.
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"
li_Success = loo_Mailman.OpenSmtpConnection()
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
return
end if
// Send the raw SMTP NOOP command (not base64-encoded).
ls_Response = loo_Mailman.SmtpSendRawCommand("NOOP","us-ascii",0)
if loo_Mailman.LastMethodSuccess = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
return
end if
Write-Debug "NOOP response: " + ls_Response
li_Success = loo_Mailman.CloseSmtpConnection()
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
return
end if
destroy loo_Mailman