Sample code for 30+ languages & platforms
Tcl

Send HTML Email with Image Downloaded from URL

Demonstrates how to compose an HTML email with an embedded image where the image data is downloaded from a URL.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

# First download the image we'll be adding to the HTML "img" tag.
set bdJpg [new_CkBinData]

set http [new_CkHttp]

set success [CkHttp_QuickGetBd $http "https://www.chilkatsoft.com/images/starfish.jpg" $bdJpg]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkBinData $bdJpg
    delete_CkHttp $http
    exit
}

set mailman [new_CkMailMan]

# Use your SMTP server..
CkMailMan_put_SmtpHost $mailman "smtp.yourserver.com"
CkMailMan_put_SmtpPort $mailman 587
CkMailMan_put_StartTLS $mailman 1

# Set the SMTP login/password
CkMailMan_put_SmtpUsername $mailman "my_login"
CkMailMan_put_SmtpPassword $mailman "my_password"

# Create an HTML email.
set email [new_CkEmail]

CkEmail_put_Subject $email "HTML Email with Image"
CkEmail_put_From $email "Dave <somebody@mydomain.com>"
CkEmail_AddTo $email "Chilkat" "info@chilkatsoft.com"

set html "<html><body><p>This is an HTML email with an embedded image.</p><p><img src=\"starfish.jpg\" /></p></body></html>"
CkEmail_SetHtmlBody $email $html

# Note: The "starfish.jpg" here must match the name in the "img" tag's "src" attribute in the HTML above.
set success [CkEmail_AddRelatedBd2 $email $bdJpg "starfish.jpg"]
if {$success == 0} then {
    puts [CkEmail_lastErrorText $email]
    delete_CkBinData $bdJpg
    delete_CkHttp $http
    delete_CkMailMan $mailman
    delete_CkEmail $email
    exit
}

CkEmail_SaveEml $email "qa_output/out.eml"

# success = mailman.SendEmail(email);
# if (success == ckfalse) {
#     println mailman.LastErrorText;
#     return;
# }
# 
# ignore = mailman.CloseSmtpConnection();

puts "Success."

delete_CkBinData $bdJpg
delete_CkHttp $http
delete_CkMailMan $mailman
delete_CkEmail $email