Sample code for 30+ languages & platforms
DataFlex

Create a Reply Email

See more Email Object Examples

Demonstrates the Chilkat Email.ToReply method, which generates a reply email with updated header and body fields so it can be sent as a reply. Attachments are excluded from the reply, but attached messages are included. The source email is not modified. This example creates a reply and prints its MIME.

Background: Replying is more than swapping sender and recipient: the To is set from the original's reply address, the subject gets an Re: prefix, the original text is quoted, and threading headers (In-Reply-To, References) are added so mail clients group the conversation. ToReply assembles all of that, leaving a message you can edit and send. Dropping attachments is the usual reply convention — you rarely echo the sender's files back to them.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Variant vReply
    Handle hoReply
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the ToReply method, which generates a reply email with updated header and
    //  body fields ready to send as a reply.  Attachments are excluded from the reply, but
    //  attached messages are included.  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 "Project update"
    Set ComFrom Of hoEmail To "alice@example.com"
    Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
    Set ComBody Of hoEmail To "Here is the project update."

    //  Create a reply email based on this message.
    Get Create (RefClass(cComChilkatEmail)) To hoReply
    If (Not(IsComObjectCreated(hoReply))) Begin
        Send CreateComObject of hoReply
    End

    Get pvComObject of hoReply to vReply
    Get ComToReply Of hoEmail vReply To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  The reply is addressed and quoted, ready to edit and send.
    Get ComGetMime Of hoReply To sTemp1
    Showln sTemp1


End_Procedure