Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C) Create AMP for EmailDemonstrates how to create an email that has the AMP for Email Format. See AMP for Email specification for more information.
#include <C_CkEmail.h> #include <C_CkStringBuilder.h> void ChilkatSample(void) { HCkEmail email; BOOL success; HCkStringBuilder sbAmp4Html; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. email = CkEmail_Create(); CkEmail_putSubject(email,"Sample AMP for Email"); CkEmail_putFrom(email,"mary@example.com"); CkEmail_AddTo(email,"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> sbAmp4Html = CkStringBuilder_Create(); CkStringBuilder_Append(sbAmp4Html,"<!doctype html>"); CkStringBuilder_Append(sbAmp4Html,"<html amp4email>"); CkStringBuilder_Append(sbAmp4Html,"<head>"); CkStringBuilder_Append(sbAmp4Html,"<meta charset=\"utf-8\">"); CkStringBuilder_Append(sbAmp4Html,"<style amp4email-boilerplate>body{visibility:hidden}</style>"); CkStringBuilder_Append(sbAmp4Html,"<script async src=\"https://cdn.ampproject.org/v0.js\"></script>"); CkStringBuilder_Append(sbAmp4Html,"</head>"); CkStringBuilder_Append(sbAmp4Html,"<body>"); CkStringBuilder_Append(sbAmp4Html,"Hello, world."); CkStringBuilder_Append(sbAmp4Html,"</body>"); CkStringBuilder_Append(sbAmp4Html,"</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: CkEmail_AddPlainTextAlternativeBody(email,"Hello World in plain text!"); // Now add the text/x-amp-html. CkEmail_SetTextBody(email,CkStringBuilder_getAsString(sbAmp4Html),"text/x-amp-html"); // Now add an HTML body.. CkEmail_AddHtmlAlternativeBody(email,"<span>Hello World in HTML!</span>"); // See what we have: printf("%s\n",CkEmail_getMime(email)); // This is the result: // (Note: Any CKX- headers produced by Chilkat are automatically removed prior to sending.) // 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 // CKX-Bounce-Address: 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-- CkEmail_Dispose(email); CkStringBuilder_Dispose(sbAmp4Html); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.