Tcl
Tcl
Verify Email Recipients Without Sending
See more SMTP Examples
Demonstrates the Chilkat MailMan.VerifyRecips method, which begins the SMTP send process for an email, sends the recipient addresses to the SMTP server, and then aborts before sending the message content. Recipient addresses rejected by the server are returned in the StringArray. This example checks two recipients and lists any that were rejected.
Background: During an SMTP transaction each recipient is offered with a
RCPT TO command, and the server accepts or rejects it before any message content is transferred. VerifyRecips exploits that: it runs the transaction just far enough to collect those verdicts, then aborts — letting you validate an address list without actually delivering mail. Note that many servers accept everything at this stage and bounce later, so a clean result is not a guarantee of deliverability.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the MailMan.VerifyRecips method, which begins the SMTP send process for an
# email, sends the recipient addresses to the SMTP server, and then aborts before sending
# the message content. Recipient addresses rejected by the server are returned in the
# StringArray.
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"
# Build an email with the recipients to verify.
set email [new_CkEmail]
CkEmail_put_Subject $email "Recipient check"
CkEmail_put_From $email "alice@example.com"
CkEmail_AddTo $email "Bob" "bob@example.com"
CkEmail_AddTo $email "Nobody" "nobody@example.com"
# Ask the server which recipients it will accept. Rejected addresses are returned.
set badAddrs [new_CkStringArray]
set success [CkMailMan_VerifyRecips $mailman $email $badAddrs]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkMailMan $mailman
delete_CkEmail $email
delete_CkStringArray $badAddrs
exit
}
set n [CkStringArray_get_Count $badAddrs]
puts "Rejected recipients: $n"
for {set i 0} {$i <= [expr $n - 1]} {incr i} {
puts [CkStringArray_getString $badAddrs $i]
}
# Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
# connects and authenticates -- using the property settings above -- whenever a server
# operation requires it. Calling the explicit connect/authenticate methods can still be
# helpful to determine whether a failure occurs while connecting or while authenticating.
delete_CkMailMan $mailman
delete_CkEmail $email
delete_CkStringArray $badAddrs