Sample code for 30+ languages & platforms
Xbase++

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

Xbase++
LOCAL nSuccess
LOCAL oEmail
LOCAL oCopy

nSuccess := 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.

oEmail := CreateObject("Chilkat.Email")
oEmail:Subject := "Original"
oEmail:From := "alice@example.com"
oEmail:AddTo("Bob", "bob@example.com")
oEmail:Body := "Original body."

//  Copy the entire email into a new Email object.
oCopy := CreateObject("Chilkat.Email")

nSuccess := oEmail:MakeCopy(oCopy)
IF (nSuccess == 0)
    ? oEmail:LastErrorText
    oEmail:destroy()
    oCopy:destroy()
    RETURN
ENDIF

? "Copy subject: " + oCopy:Subject
? "Copy NumTo: " + Str(oCopy:NumTo)

oEmail:destroy()
oCopy:destroy()