Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.0.0+

Build an AMP email with text and HTML fallbacks

See more Email Object Examples

Place text/x-amp-html inside multipart/alternative, before the regular HTML alternative. Use the AMP email validator and meet your provider’s sender requirements before using a dynamic campaign. AMP email MIME structure.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Variant vMimeBytes
    Handle hoMimeBytes
    Handle hoMime
    Variant vSpecial
    Handle hoSpecial
    Variant vStandard
    Handle hoStandard
    String sTemp1

    Move False To iSuccess

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComFrom Of hoEmail To "Workshop team <events@example.com>"
    Get ComAddTo Of hoEmail "Alex Rivera" "alex@example.net" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Set ComSubject Of hoEmail To "Workshop reminder"
    Set ComBody Of hoEmail To "Your workshop starts at 09:00."
    Get Create (RefClass(cComChilkatBinData)) To hoMimeBytes
    If (Not(IsComObjectCreated(hoMimeBytes))) Begin
        Send CreateComObject of hoMimeBytes
    End
    Get pvComObject of hoMimeBytes to vMimeBytes
    Get ComGetMimeBd Of hoEmail vMimeBytes To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatMime)) To hoMime
    If (Not(IsComObjectCreated(hoMime))) Begin
        Send CreateComObject of hoMime
    End
    Get pvComObject of hoMimeBytes to vMimeBytes
    Get ComLoadMimeBd Of hoMime vMimeBytes To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComConvertToMultipartAlt Of hoMime To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Append the specialist part before the standard HTML fallback.
    Get Create (RefClass(cComChilkatMime)) To hoSpecial
    If (Not(IsComObjectCreated(hoSpecial))) Begin
        Send CreateComObject of hoSpecial
    End
    Set ComContentType Of hoSpecial To "text/x-amp-html"
    Set ComCharset Of hoSpecial To "utf-8"
    Send ComSetBody To hoSpecial "<!doctype html><html amp4email><head><meta charset='utf-8'><style amp4email-boilerplate>body{visibility:hidden}</style><script async src='https://cdn.ampproject.org/v0.js'></script></head><body><p>Your workshop starts at 09:00.</p></body></html>"
    Get pvComObject of hoSpecial to vSpecial
    Get ComAppendPart Of hoMime vSpecial To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatMime)) To hoStandard
    If (Not(IsComObjectCreated(hoStandard))) Begin
        Send CreateComObject of hoStandard
    End
    Set ComContentType Of hoStandard To "text/html"
    Set ComCharset Of hoStandard To "utf-8"
    Send ComSetBody To hoStandard "<p>Your workshop starts at <b>09:00</b>.</p>"
    Get pvComObject of hoStandard to vStandard
    Get ComAppendPart Of hoMime vStandard To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComSaveMime Of hoMime "amp.eml" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Saved amp.eml."


End_Procedure