DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMailman
String sResponse
String sTemp1
Boolean bTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatMailMan)) To hoMailman
If (Not(IsComObjectCreated(hoMailman))) Begin
Send CreateComObject of hoMailman
End
// Configure the SMTP server connection.
Set ComSmtpHost Of hoMailman To "smtp.example.com"
Set ComSmtpPort Of hoMailman To 465
Set ComSmtpSsl Of hoMailman To True
Set ComSmtpUsername Of hoMailman To "user@example.com"
Set ComSmtpPassword Of hoMailman To "myPassword"
Get ComOpenSmtpConnection Of hoMailman To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
// Send the raw SMTP NOOP command (not base64-encoded).
Get ComSmtpSendRawCommand Of hoMailman "NOOP" "us-ascii" False To sResponse
Get ComLastMethodSuccess Of hoMailman To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "NOOP response: " sResponse
Get ComCloseSmtpConnection Of hoMailman To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure