Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.0.0+

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

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Email

li_Success = 0

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.FromName = "Sam Lee"
loo_Email.FromAddress = "sam@example.com"
loo_Email.ReplyTo = "replies@example.com"
li_Success = loo_Email.AddTo("Alex Rivera","alex@example.net")
if li_Success <> 1 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

loo_Email.Subject = "Sample message"
loo_Email.Charset = "utf-8"
//  A custom header can carry a reference alongside the standard message fields.
loo_Email.AddHeaderField("X-Reference-ID","REF-42")
li_Success = loo_Email.AddPlainTextAlternativeBody("Read more at https://example.com/details.")
if li_Success <> 1 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

li_Success = loo_Email.AddHtmlAlternativeBody("<p><a href='https://example.com/details'>Read more</a></p>")
if li_Success <> 1 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

li_Success = loo_Email.SaveEml("text-and-html.eml")
if li_Success <> 1 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

Write-Debug "Saved text-and-html.eml."


destroy loo_Email