PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkEmail.pb"
Procedure ChilkatExample()
success.i = 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.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Original")
CkEmail::setCkFrom(email, "alice@example.com")
CkEmail::ckAddTo(email,"Bob","bob@example.com")
CkEmail::setCkBody(email, "Original body.")
; Copy the entire email into a new Email object.
copy.i = CkEmail::ckCreate()
If copy.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkEmail::ckMakeCopy(email,copy)
If success = 0
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
CkEmail::ckDispose(copy)
ProcedureReturn
EndIf
Debug "Copy subject: " + CkEmail::ckSubject(copy)
Debug "Copy NumTo: " + Str(CkEmail::ckNumTo(copy))
CkEmail::ckDispose(email)
CkEmail::ckDispose(copy)
ProcedureReturn
EndProcedure