Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

SQL Server Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(SQL Server) Create AMP for Email

Demonstrates how to create an email that has the AMP for Email Format.

See AMP for Email specification for more information.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @email int
    -- Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @email, 'Subject', 'Sample AMP for Email'
    EXEC sp_OASetProperty @email, 'From', 'mary@example.com'
    EXEC sp_OAMethod @email, 'AddTo', @success OUT, '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>

    DECLARE @sbAmp4Html int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbAmp4Html OUT

    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '<!doctype html>'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '<html amp4email>'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '<head>'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '<meta charset="utf-8">'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '<style amp4email-boilerplate>body{visibility:hidden}</style>'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '<script async src="https://cdn.ampproject.org/v0.js"></script>'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '</head>'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '<body>'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, 'Hello, world.'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '</body>'
    EXEC sp_OAMethod @sbAmp4Html, 'Append', @success OUT, '</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:
    EXEC sp_OAMethod @email, 'AddPlainTextAlternativeBody', @success OUT, 'Hello World in plain text!'

    -- Now add the text/x-amp-html.
    EXEC sp_OAMethod @sbAmp4Html, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @email, 'SetTextBody', NULL, @sTmp0, 'text/x-amp-html'

    -- Now add an HTML body..
    EXEC sp_OAMethod @email, 'AddHtmlAlternativeBody', @success OUT, '<span>Hello World in HTML!</span>'

    -- See what we have:
    EXEC sp_OAMethod @email, 'GetMime', @sTmp0 OUT
    PRINT @sTmp0

    -- 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--

    EXEC @hr = sp_OADestroy @email
    EXEC @hr = sp_OADestroy @sbAmp4Html


END
GO

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.