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
(Lianja) 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.)
// 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. loMailman = createobject("CkMailMan") // Use your SMTP server hostname. This example uses office365, but it could be any SMTP server.. loMailman.SmtpHost = "outlook.office365.com" loMailman.SmtpPort = 587 loMailman.StartTLS = .T. // Set the SMTP login/password loMailman.SmtpUsername = "OFFICE365-SMTP-LOGIN" loMailman.SmtpPassword = "OFFICE365-SMTP-PASSWORD" // Create a new email object loEmail = createobject("CkEmail") loEmail.Subject = "HTML Email with embedded CSS" loEmail.From = "Chilkat Support <my-office365-user@mydomain.com>" loEmail.AddTo("Chilkat Support","support@chilkatsoft.com") loSbCss = createobject("CkStringBuilder") llBCrlf = .T. loSbCss.AppendLine("body {",llBCrlf) loSbCss.AppendLine(" background-color: powderblue;",llBCrlf) loSbCss.AppendLine("}",llBCrlf) loSbCss.AppendLine("h1 {",llBCrlf) loSbCss.AppendLine(" color: blue;",llBCrlf) loSbCss.AppendLine("}",llBCrlf) loSbCss.AppendLine("p {",llBCrlf) loSbCss.AppendLine(" color: red;",llBCrlf) loSbCss.AppendLine("}",llBCrlf) // The filenameInHtml is what should exists within the HTML (in the href atribute) lcFilenameInHtml = "styles.css" // Call AddRelatedString2 to use Content-Location. loEmail.AddRelatedString2(lcFilenameInHtml,loSbCss.GetAsString(),"utf-8") loSbHtml = createobject("CkStringBuilder") loSbHtml.AppendLine("<!DOCTYPE html>",llBCrlf) loSbHtml.AppendLine("<html>",llBCrlf) loSbHtml.AppendLine("<head>",llBCrlf) loSbHtml.AppendLine(' <link rel="stylesheet" href="styles.css">',llBCrlf) loSbHtml.AppendLine("</head>",llBCrlf) loSbHtml.AppendLine("<body>",llBCrlf) loSbHtml.AppendLine("",llBCrlf) loSbHtml.AppendLine("<h1>This is a heading</h1>",llBCrlf) loSbHtml.AppendLine("<p>This is a paragraph.</p>",llBCrlf) loSbHtml.AppendLine("",llBCrlf) loSbHtml.AppendLine("</body>",llBCrlf) loSbHtml.AppendLine("</html>",llBCrlf) loEmail.SetHtmlBody(loSbHtml.GetAsString()) llSuccess = loMailman.SendEmail(loEmail) if (llSuccess <> .T.) then ? loMailman.LastErrorText else ? "Mail Sent!" endif release loMailman release loEmail release loSbCss release loSbHtml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.