DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoEmail
Variant vCopy
Handle hoCopy
String sTemp1
Integer iTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Original"
Set ComFrom Of hoEmail To "alice@example.com"
Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
Set ComBody Of hoEmail To "Original body."
// Copy the entire email into a new Email object.
Get Create (RefClass(cComChilkatEmail)) To hoCopy
If (Not(IsComObjectCreated(hoCopy))) Begin
Send CreateComObject of hoCopy
End
Get pvComObject of hoCopy to vCopy
Get ComMakeCopy Of hoEmail vCopy To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComSubject Of hoCopy To sTemp1
Showln "Copy subject: " sTemp1
Get ComNumTo Of hoCopy To iTemp1
Showln "Copy NumTo: " iTemp1
End_Procedure