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

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

 

 

 

(DataFlex) 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 ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoMailman
    Variant vEmail
    Handle hoEmail
    Handle hoSbCss
    Boolean iBCrlf
    String sFilenameInHtml
    String sContentIdCss
    Handle hoSbHtml
    Integer iNumReplacements
    Boolean iSuccess
    String sTemp1
    Boolean bTemp1

    //  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.
    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    //  Use your SMTP server hostname.  This example uses office365, but it could be any SMTP server..
    Set ComSmtpHost Of hoMailman To "outlook.office365.com"
    Set ComSmtpPort Of hoMailman To 587
    Set ComStartTLS Of hoMailman To True

    //  Set the SMTP login/password
    Set ComSmtpUsername Of hoMailman To "OFFICE365-SMTP-LOGIN"
    Set ComSmtpPassword Of hoMailman To "OFFICE365-SMTP-PASSWORD"

    //  Create a new email object
    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "HTML Email with embedded CSS"
    Set ComFrom Of hoEmail To "Chilkat Support <my-office365-user@mydomain.com>"
    Get ComAddTo Of hoEmail "Chilkat Support" "support@chilkatsoft.com" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbCss
    If (Not(IsComObjectCreated(hoSbCss))) Begin
        Send CreateComObject of hoSbCss
    End
    Move True To iBCrlf
    Get ComAppendLine Of hoSbCss "body {" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbCss "    background-color: powderblue;" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbCss "}" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbCss "h1 {" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbCss "    color: blue;" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbCss "}" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbCss "p {" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbCss "    color: red;" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbCss "}" iBCrlf To iSuccess

    //  It's possible to add a CSS file directly by calling AddRelatedFile.
    //  This example will add the CSS from a string.
    Move "styles.css" To sFilenameInHtml
    Get ComGetAsString Of hoSbCss To sTemp1
    Get ComAddRelatedString Of hoEmail sFilenameInHtml sTemp1 "utf-8" To sContentIdCss
    Get ComLastMethodSuccess Of hoEmail To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  The src attribute for the image tag is set to the contentIdCss:
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbHtml
    If (Not(IsComObjectCreated(hoSbHtml))) Begin
        Send CreateComObject of hoSbHtml
    End
    Get ComAppendLine Of hoSbHtml "<!DOCTYPE html>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "<html>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "<head>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml '  <link rel="stylesheet" href="cid:CONTENT_ID_CSS">' iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "</head>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "<body>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "<h1>This is a heading</h1>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "<p>This is a paragraph.</p>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "</body>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "</html>" iBCrlf To iSuccess

    Get ComReplace Of hoSbHtml "CONTENT_ID_CSS" sContentIdCss To iNumReplacements

    Get ComGetAsString Of hoSbHtml To sTemp1
    Send ComSetHtmlBody To hoEmail sTemp1

    Get pvComObject of hoEmail to vEmail
    Get ComSendEmail Of hoMailman vEmail To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
    End
    Else Begin
        Showln "Mail Sent!"
    End



End_Procedure

 

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