Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

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

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"

set success [CkMailMan_OpenSmtpConnection $mailman]
if {$success == 0} then {
    puts [CkMailMan_lastErrorText $mailman]
    delete_CkMailMan $mailman
    exit
}

#  Send the raw SMTP NOOP command (not base64-encoded).
set response [CkMailMan_smtpSendRawCommand $mailman "NOOP" "us-ascii" 0]
if {[CkMailMan_get_LastMethodSuccess $mailman] == 0} then {
    puts [CkMailMan_lastErrorText $mailman]
    delete_CkMailMan $mailman
    exit
}

puts "NOOP response: $response"

set success [CkMailMan_CloseSmtpConnection $mailman]
if {$success == 0} then {
    puts [CkMailMan_lastErrorText $mailman]
    delete_CkMailMan $mailman
    exit
}


delete_CkMailMan $mailman