Tcl
Tcl
Send a Bundle of Emails via SMTP
See more SMTP Examples
Demonstrates the Chilkat MailMan.SendBundle method, which sends each email in an EmailBundle. This is equivalent to calling SendEmail once for each email in the bundle. This example builds a bundle of two messages and sends them.
Background: Sending a bundle lets Chilkat reuse a single SMTP connection for all the messages, avoiding the connect/authenticate overhead of sending them one at a time — the same efficiency as the explicit open/send-loop/close pattern, in one call. It is handy for dispatching a queued batch of distinct messages (as opposed to one message to many recipients).
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the MailMan.SendBundle method, which sends each email in an EmailBundle.
# This is equivalent to calling SendEmail once for each email in the bundle.
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 a bundle of emails to send.
set bundle [new_CkEmailBundle]
set email1 [new_CkEmail]
CkEmail_put_Subject $email1 "Message 1"
CkEmail_put_From $email1 "alice@example.com"
CkEmail_AddTo $email1 "Bob" "bob@example.com"
CkEmail_put_Body $email1 "This is the first message."
CkEmailBundle_AddEmail $bundle $email1
set email2 [new_CkEmail]
CkEmail_put_Subject $email2 "Message 2"
CkEmail_put_From $email2 "alice@example.com"
CkEmail_AddTo $email2 "Carol" "carol@example.com"
CkEmail_put_Body $email2 "This is the second message."
CkEmailBundle_AddEmail $bundle $email2
# Send every email in the bundle.
set success [CkMailMan_SendBundle $mailman $bundle]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkMailMan $mailman
delete_CkEmailBundle $bundle
delete_CkEmail $email1
delete_CkEmail $email2
exit
}
puts "Sent [CkEmailBundle_get_MessageCount $bundle] emails."
# 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_CkEmailBundle $bundle
delete_CkEmail $email1
delete_CkEmail $email2