Tcl
Tcl
Send an Email via SMTP
See more SMTP Examples
Demonstrates the Chilkat MailMan.SendEmail method, which sends a single Email object through the configured SMTP server. This example configures the SMTP connection, builds a message, and sends it.
Background: SMTP (Simple Mail Transfer Protocol) is the protocol for sending mail. The typical flow is: connect to the server, authenticate, then hand over the message with
MAIL FROM, RCPT TO, and DATA. SendEmail wraps all of that: you build an Email with subject, recipients, and body, and Chilkat renders it to MIME and delivers it. Modern submission commonly uses implicit TLS on port 465 (SmtpSsl = true).Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the MailMan.SendEmail method, which sends a single Email object through the
# configured SMTP server.
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 the email to send.
set email [new_CkEmail]
CkEmail_put_Subject $email "Test email from Chilkat"
CkEmail_put_From $email "alice@example.com"
CkEmail_AddTo $email "Bob" "bob@example.com"
CkEmail_put_Body $email "Hello, this is a test message."
# Send the email.
set success [CkMailMan_SendEmail $mailman $email]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkMailMan $mailman
delete_CkEmail $email
exit
}
puts "Email sent."
# 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