Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_BdJpg
oleobject loo_Http
oleobject loo_Mailman
oleobject loo_Email
string ls_Html

li_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.
loo_BdJpg = create oleobject
li_rc = loo_BdJpg.ConnectToNewObject("Chilkat.BinData")
if li_rc < 0 then
    destroy loo_BdJpg
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

li_Success = loo_Http.QuickGetBd("https://www.chilkatsoft.com/images/starfish.jpg",loo_BdJpg)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_BdJpg
    destroy loo_Http
    return
end if

loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")

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

// Set the SMTP login/password
loo_Mailman.SmtpUsername = "my_login"
loo_Mailman.SmtpPassword = "my_password"

// Create an HTML email.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")

loo_Email.Subject = "HTML Email with Image"
loo_Email.From = "Dave <somebody@mydomain.com>"
loo_Email.AddTo("Chilkat","info@chilkatsoft.com")

ls_Html = "<html><body><p>This is an HTML email with an embedded image.</p><p><img src=~"starfish.jpg~" /></p></body></html>"
loo_Email.SetHtmlBody(ls_Html)

// Note: The "starfish.jpg" here must match the name in the "img" tag's "src" attribute in the HTML above.
li_Success = loo_Email.AddRelatedBd2(loo_BdJpg,"starfish.jpg")
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_BdJpg
    destroy loo_Http
    destroy loo_Mailman
    destroy loo_Email
    return
end if

loo_Email.SaveEml("qa_output/out.eml")

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

Write-Debug "Success."


destroy loo_BdJpg
destroy loo_Http
destroy loo_Mailman
destroy loo_Email