Tcl Requires Chilkat v11.0.0+
Tcl
Create an email with plain-text and HTML bodies
See more Email Object Examples
Set the From and Reply-To addresses, add a recipient, and provide plain-text and HTML versions of the same body. Save the message as text-and-html.eml.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Assumes Chilkat is unlocked. See Global Unlock Sample.
set email [new_CkEmail]
CkEmail_put_FromName $email "Sam Lee"
CkEmail_put_FromAddress $email "sam@example.com"
CkEmail_put_ReplyTo $email "replies@example.com"
set success [CkEmail_AddTo $email "Alex Rivera" "alex@example.net"]
if {$success != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
exit
}
CkEmail_put_Subject $email "Sample message"
CkEmail_put_Charset $email "utf-8"
# A custom header can carry a reference alongside the standard message fields.
CkEmail_AddHeaderField $email "X-Reference-ID" "REF-42"
set success [CkEmail_AddPlainTextAlternativeBody $email "Read more at https://example.com/details."]
if {$success != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
exit
}
set success [CkEmail_AddHtmlAlternativeBody $email "<p><a href='https://example.com/details'>Read more</a></p>"]
if {$success != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
exit
}
set success [CkEmail_SaveEml $email "text-and-html.eml"]
if {$success != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
exit
}
puts "Saved text-and-html.eml."
delete_CkEmail $email