Sample code for 30+ languages & platforms
PowerBuilder

Make a Copy of an Email

See more Email Object Examples

Demonstrates the Chilkat Email.MakeCopy method, which copies the entire state of this email into another Email object — message content, recipients, headers, body representations, attachments, and related items. This example copies an email and reads a couple of fields from the copy.

Background: A deep copy gives you an independent duplicate: changes to one object do not affect the other. This is handy for template-and-tweak workflows — build a base message once, copy it per recipient, then vary only the recipient or a few fields — without risk of one send's edits bleeding into the next.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Copy

li_Success = 0

//  Demonstrates the MakeCopy method, which copies the entire state of this email into
//  another Email object -- message content, recipients, headers, bodies, attachments, and
//  related items.

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.Subject = "Original"
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
loo_Email.Body = "Original body."

//  Copy the entire email into a new Email object.
loo_Copy = create oleobject
li_rc = loo_Copy.ConnectToNewObject("Chilkat.Email")

li_Success = loo_Email.MakeCopy(loo_Copy)
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    destroy loo_Copy
    return
end if

Write-Debug "Copy subject: " + loo_Copy.Subject
Write-Debug "Copy NumTo: " + string(loo_Copy.NumTo)


destroy loo_Email
destroy loo_Copy