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
(Unicode C++) Send HTML Email with CSS as Related Item using Content-LocationDemonstrates how to compose an HTML email with an external CSS file included as a related item and referenced by Content-Location. Some email clients display embedded (related) content best using CID's (Content-IDs), whereas other email clients display related content best by Content-Location. The choice you make may depend on the software used by the intended recipient of your email. (Does' the recipient read email on an iPhone? Android? Outlook? GMail? Thunderbird? etc.)
#include <CkMailManW.h> #include <CkEmailW.h> #include <CkStringBuilderW.h> void ChilkatSample(void) { // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample 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); // The filenameInHtml is what should exists within the HTML (in the href atribute) const wchar_t *filenameInHtml = L"styles.css"; // Call AddRelatedString2 to use Content-Location. email.AddRelatedString2(filenameInHtml,sbCss.getAsString(),L"utf-8"); 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=\"styles.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); 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-2024 Chilkat Software, Inc. All Rights Reserved.