Sample code for 30+ languages & platforms
DataFlex

Create an Inline-Forward Email

See more Email Object Examples

Demonstrates the Chilkat Email.ToForward method, which creates an inline-forward email based on this email. The forward is returned in the argument, and the source email is not modified. The returned email can be edited — adding recipients, prepending a note — before sending. This example forwards a message and adds a recipient.

Background: An inline forward quotes the original message's content within the body of the new message — the familiar "---------- Forwarded message ----------" style — as opposed to attaching the original as a message/rfc822 part (which AttachEmail does). Chilkat assembles the quoted body and headers for you, leaving the new message ready to address and send.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Variant vFwd
    Handle hoFwd
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the ToForward method, which creates an inline-forward email based on this
    //  email.  The forward is returned in the argument; the source email is not modified.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "Quarterly results"
    Set ComFrom Of hoEmail To "alice@example.com"
    Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
    Set ComBody Of hoEmail To "Here are the quarterly results."

    //  Create an inline-forward email from this message.
    Get Create (RefClass(cComChilkatEmail)) To hoFwd
    If (Not(IsComObjectCreated(hoFwd))) Begin
        Send CreateComObject of hoFwd
    End

    Get pvComObject of hoFwd to vFwd
    Get ComToForward Of hoEmail vFwd To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  The forward can be edited to add recipients before sending.
    Get ComAddTo Of hoFwd "Carol" "carol@example.com" To iSuccess

    Get ComGetMime Of hoFwd To sTemp1
    Showln sTemp1


End_Procedure