DataFlex
DataFlex
Create AMP for Email
See more Email Object Examples
Demonstrates how to create an email that has the AMP for Email Format.See AMP for Email specification for more information.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoEmail
Handle hoSbAmp4Html
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Sample AMP for Email"
Set ComFrom Of hoEmail To "mary@example.com"
Get ComAddTo Of hoEmail "Joe" "joe@example.com" To iSuccess
// Create the following AMP for Email HTML
// <!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>
// Hello, world.
// </body>
// </html>
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbAmp4Html
If (Not(IsComObjectCreated(hoSbAmp4Html))) Begin
Send CreateComObject of hoSbAmp4Html
End
Get ComAppend Of hoSbAmp4Html "<!doctype html>" To iSuccess
Get ComAppend Of hoSbAmp4Html "<html amp4email>" To iSuccess
Get ComAppend Of hoSbAmp4Html "<head>" To iSuccess
Get ComAppend Of hoSbAmp4Html '<meta charset="utf-8">' To iSuccess
Get ComAppend Of hoSbAmp4Html "<style amp4email-boilerplate>body{visibility:hidden}</style>" To iSuccess
Get ComAppend Of hoSbAmp4Html '<script async src="https://cdn.ampproject.org/v0.js"></script>' To iSuccess
Get ComAppend Of hoSbAmp4Html "</head>" To iSuccess
Get ComAppend Of hoSbAmp4Html "<body>" To iSuccess
Get ComAppend Of hoSbAmp4Html "Hello, world." To iSuccess
Get ComAppend Of hoSbAmp4Html "</body>" To iSuccess
Get ComAppend Of hoSbAmp4Html "</html>" To iSuccess
// We want to build a multipart/alternative email, where the 1st alternative body
// is text/plain, the 2nd is text/x-amp-html, and the last is text/html.
// (Some email clients will only render the last MIME part, so we recommend placing the text/x-amp-html MIME part before the text/html MIME part.)
// First create a plain-text email body:
Get ComAddPlainTextAlternativeBody Of hoEmail "Hello World in plain text!" To iSuccess
// Now add the text/x-amp-html.
Get ComGetAsString Of hoSbAmp4Html To sTemp1
Send ComSetTextBody To hoEmail sTemp1 "text/x-amp-html"
// Now add an HTML body..
Get ComAddHtmlAlternativeBody Of hoEmail "<span>Hello World in HTML!</span>" To iSuccess
// See what we have:
Get ComGetMime Of hoEmail To sTemp1
Showln sTemp1
// This is the result:
// MIME-Version: 1.0
// Date: Thu, 30 May 2019 09:37:56 -0500
// Message-ID: <923A689FF657170A9F662B4CE87978AB1EBD4DBD@CHILKATSLICE>
// Content-Type: multipart/alternative;
// boundary="------------040205090807060906020803"
// X-Priority: 3 (Normal)
// Subject: Sample AMP for Email
// From: mary@example.com
// To: Joe <joe@example.com>
//
// --------------040205090807060906020803
// Content-Transfer-Encoding: 7bit
// Content-Type: text/plain; charset=us-ascii; format=flowed
//
// Hello World in plain text!
// --------------040205090807060906020803
// Content-Transfer-Encoding: 7bit
// Content-Type: text/x-amp-html; charset=us-ascii
//
// <!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>Hello, world.</body></html>
// --------------040205090807060906020803
// Content-Transfer-Encoding: 7bit
// Content-Type: text/html; charset=us-ascii
//
// <span>Hello World in HTML!</span>
//
// --------------040205090807060906020803--
End_Procedure