Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Unicode C++ Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Unicode C++) Send HTML Email with External CSS as Related Item

Demonstrates how to compose an HTML email with an external CSS file included as a related item and referenced by CID (Content-ID).

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <CkMailManW.h>
#include <CkEmailW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    //  This example requires the Chilkat Email API to have been previously unlocked.
    //  See Unlock Chilkat MailMan for sample code.

    //  The mailman object is used for sending and receiving email.
    CkMailManW mailman;

    //  Use your SMTP server hostname.  This example uses office365, but it could be any SMTP server..
    mailman.put_SmtpHost(L"outlook.office365.com");
    mailman.put_SmtpPort(587);
    mailman.put_StartTLS(true);

    //  Set the SMTP login/password
    mailman.put_SmtpUsername(L"OFFICE365-SMTP-LOGIN");
    mailman.put_SmtpPassword(L"OFFICE365-SMTP-PASSWORD");

    //  Create a new email object
    CkEmailW email;
    email.put_Subject(L"HTML Email with embedded CSS");
    email.put_From(L"Chilkat Support <my-office365-user@mydomain.com>");
    email.AddTo(L"Chilkat Support",L"support@chilkatsoft.com");

    CkStringBuilderW sbCss;
    bool bCrlf = true;
    sbCss.AppendLine(L"body {",bCrlf);
    sbCss.AppendLine(L"    background-color: powderblue;",bCrlf);
    sbCss.AppendLine(L"}",bCrlf);
    sbCss.AppendLine(L"h1 {",bCrlf);
    sbCss.AppendLine(L"    color: blue;",bCrlf);
    sbCss.AppendLine(L"}",bCrlf);
    sbCss.AppendLine(L"p {",bCrlf);
    sbCss.AppendLine(L"    color: red;",bCrlf);
    sbCss.AppendLine(L"}",bCrlf);

    //  It's possible to add a CSS file directly by calling AddRelatedFile.
    //  This example will add the CSS from a string.
    const wchar_t *filenameInHtml = L"styles.css";
    const wchar_t *contentIdCss = email.addRelatedString(filenameInHtml,sbCss.getAsString(),L"utf-8");
    if (email.get_LastMethodSuccess() != true) {
        wprintf(L"%s\n",email.lastErrorText());
        return;
    }

    //  The src attribute for the image tag is set to the contentIdCss:
    CkStringBuilderW sbHtml;
    sbHtml.AppendLine(L"<!DOCTYPE html>",bCrlf);
    sbHtml.AppendLine(L"<html>",bCrlf);
    sbHtml.AppendLine(L"<head>",bCrlf);
    sbHtml.AppendLine(L"  <link rel=\"stylesheet\" href=\"cid:CONTENT_ID_CSS\">",bCrlf);
    sbHtml.AppendLine(L"</head>",bCrlf);
    sbHtml.AppendLine(L"<body>",bCrlf);
    sbHtml.AppendLine(L"",bCrlf);
    sbHtml.AppendLine(L"<h1>This is a heading</h1>",bCrlf);
    sbHtml.AppendLine(L"<p>This is a paragraph.</p>",bCrlf);
    sbHtml.AppendLine(L"",bCrlf);
    sbHtml.AppendLine(L"</body>",bCrlf);
    sbHtml.AppendLine(L"</html>",bCrlf);

    int numReplacements = sbHtml.Replace(L"CONTENT_ID_CSS",contentIdCss);

    email.SetHtmlBody(sbHtml.getAsString());

    bool success = mailman.SendEmail(email);
    if (success != true) {
        wprintf(L"%s\n",mailman.lastErrorText());
    }
    else {
        wprintf(L"Mail Sent!\n");
    }
    }

 

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