PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_SbAmp4Html
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
destroy loo_Email
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Email.Subject = "Sample AMP for Email"
loo_Email.From = "mary@example.com"
loo_Email.AddTo("Joe","joe@example.com")
// 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>
loo_SbAmp4Html = create oleobject
li_rc = loo_SbAmp4Html.ConnectToNewObject("Chilkat.StringBuilder")
loo_SbAmp4Html.Append("<!doctype html>")
loo_SbAmp4Html.Append("<html amp4email>")
loo_SbAmp4Html.Append("<head>")
loo_SbAmp4Html.Append("<meta charset=~"utf-8~">")
loo_SbAmp4Html.Append("<style amp4email-boilerplate>body{visibility:hidden}</style>")
loo_SbAmp4Html.Append("<script async src=~"https://cdn.ampproject.org/v0.js~"></script>")
loo_SbAmp4Html.Append("</head>")
loo_SbAmp4Html.Append("<body>")
loo_SbAmp4Html.Append("Hello, world.")
loo_SbAmp4Html.Append("</body>")
loo_SbAmp4Html.Append("</html>")
// 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:
loo_Email.AddPlainTextAlternativeBody("Hello World in plain text!")
// Now add the text/x-amp-html.
loo_Email.SetTextBody(loo_SbAmp4Html.GetAsString(),"text/x-amp-html")
// Now add an HTML body..
loo_Email.AddHtmlAlternativeBody("<span>Hello World in HTML!</span>")
// See what we have:
Write-Debug loo_Email.GetMime()
// 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--
destroy loo_Email
destroy loo_SbAmp4Html