Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oBdJpg
LOCAL oHttp
LOCAL oMailman
LOCAL oEmail
LOCAL cHtml

nSuccess := 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.
oBdJpg := CreateObject("Chilkat.BinData")
oHttp := CreateObject("Chilkat.Http")
nSuccess := oHttp:QuickGetBd("https://www.chilkatsoft.com/images/starfish.jpg", oBdJpg)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oBdJpg:destroy()
    oHttp:destroy()
    RETURN
ENDIF

oMailman := CreateObject("Chilkat.MailMan")

//  Use your SMTP server..
oMailman:SmtpHost := "smtp.yourserver.com"
oMailman:SmtpPort := 587
oMailman:StartTLS := 1

//  Set the SMTP login/password
oMailman:SmtpUsername := "my_login"
oMailman:SmtpPassword := "my_password"

//  Create an HTML email.
oEmail := CreateObject("Chilkat.Email")
oEmail:Subject := "HTML Email with Image"
oEmail:From := "Dave <somebody@mydomain.com>"
oEmail:AddTo("Chilkat", "info@chilkatsoft.com")

cHtml := '<html><body><p>This is an HTML email with an embedded image.</p><p><img src="starfish.jpg" /></p></body></html>'
oEmail:SetHtmlBody(cHtml)

//  Note: The "starfish.jpg" here must match the name in the "img" tag's "src" attribute in the HTML above.
nSuccess := oEmail:AddRelatedBd2(oBdJpg, "starfish.jpg")
IF (nSuccess == 0)
    ? oEmail:LastErrorText
    oBdJpg:destroy()
    oHttp:destroy()
    oMailman:destroy()
    oEmail:destroy()
    RETURN
ENDIF

oEmail:SaveEml("qa_output/out.eml")

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

? "Success."

oBdJpg:destroy()
oHttp:destroy()
oMailman:destroy()
oEmail:destroy()