Sample code for 30+ languages & platforms
DataFlex

Set the Email From Header

See more Email Object Examples

Demonstrates the Chilkat Email.From property, which contains the sender name and email address as they appear in the MIME From header, such as John Smith <john.smith@example.com>. The From, FromName, and FromAddress properties are different views of the same MIME From header. This example sets From and reads back all three views.

Background: The internet message standard (RFC 5322) formats a sender as an optional display name followed by the address in angle brackets: Display Name <user@domain>. The display name is what a mail client typically shows in the inbox, while the bracketed address is the actual routing destination. Note that this visible From header is separate from the SMTP envelope sender used during delivery, which is why spoofing a From is possible — and why standards like SPF, DKIM, and DMARC exist to verify it.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    String sTemp1

    //  Demonstrates the Email.From property, which contains the sender name and
    //  email address as they appear in the From header, such as
    //  "John Smith <john.smith@example.com>".
    //  From, FromName, and FromAddress are different views of the same From header.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Set ComFrom Of hoEmail To "John Smith <john.smith@example.com>"

    Get ComFrom Of hoEmail To sTemp1
    Showln "From = " sTemp1
    Get ComFromName Of hoEmail To sTemp1
    Showln "FromName = " sTemp1
    Get ComFromAddress Of hoEmail To sTemp1
    Showln "FromAddress = " sTemp1


End_Procedure