PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkMailMan.pb"
Procedure ChilkatExample()
success.i = 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.
mailman.i = CkMailMan::ckCreate()
If mailman.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Configure the SMTP server connection.
CkMailMan::setCkSmtpHost(mailman, "smtp.example.com")
CkMailMan::setCkSmtpPort(mailman, 465)
CkMailMan::setCkSmtpSsl(mailman, 1)
CkMailMan::setCkSmtpUsername(mailman, "user@example.com")
CkMailMan::setCkSmtpPassword(mailman, "myPassword")
success = CkMailMan::ckOpenSmtpConnection(mailman)
If success = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
ProcedureReturn
EndIf
; Send the raw SMTP NOOP command (not base64-encoded).
response.s = CkMailMan::ckSmtpSendRawCommand(mailman,"NOOP","us-ascii",0)
If CkMailMan::ckLastMethodSuccess(mailman) = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
ProcedureReturn
EndIf
Debug "NOOP response: " + response
success = CkMailMan::ckCloseSmtpConnection(mailman)
If success = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
ProcedureReturn
EndIf
CkMailMan::ckDispose(mailman)
ProcedureReturn
EndProcedure