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

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

 

 

 

(C) Send HTML Email with Embedded Image Loaded from Memory

Demonstrates how to compose an HTML email with an embedded image where the image data is loaded directly from memory.

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 <C_CkFileAccess.h>
#include <C_CkByteData.h>
#include <C_CkMailMan.h>
#include <C_CkEmail.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkFileAccess fac;
    HCkByteData imageBytes;
    HCkMailMan mailman;
    HCkEmail email;
    const char *contentIdStarfish;
    HCkStringBuilder sbHtml;
    int numReplacements;
    BOOL success;

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

    //  First load image data into memory.
    //  This example loads image data from a file.
    //  However, your application could get the image data from any other source, such as
    //  from a database.
    fac = CkFileAccess_Create();
    imageBytes = CkByteData_Create();
    success = CkFileAccess_ReadEntireFile(fac,"qa_data/jpg/starfish.jpg",imageBytes);

    //  The mailman object is used for sending and receiving email.
    mailman = CkMailMan_Create();

    //  Use your SMTP server hostname.  This example uses office365, but it could be any SMTP server..
    CkMailMan_putSmtpHost(mailman,"outlook.office365.com");
    CkMailMan_putSmtpPort(mailman,587);
    CkMailMan_putStartTLS(mailman,TRUE);

    //  Set the SMTP login/password
    CkMailMan_putSmtpUsername(mailman,"OFFICE365-SMTP-LOGIN");
    CkMailMan_putSmtpPassword(mailman,"OFFICE365-SMTP-PASSWORD");

    //  Create a new email object
    email = CkEmail_Create();
    CkEmail_putSubject(email,"HTML Email with Image Loaded from In-Memory Bytes");
    CkEmail_putFrom(email,"Chilkat Support <my-office365-user@mydomain.com>");
    CkEmail_AddTo(email,"Chilkat Support","support@chilkatsoft.com");

    contentIdStarfish = CkEmail_addRelatedData(email,"starfish.jpg",imageBytes);
    if (CkEmail_getLastMethodSuccess(email) != TRUE) {
        printf("%s\n",CkEmail_lastErrorText(email));
        CkFileAccess_Dispose(fac);
        CkByteData_Dispose(imageBytes);
        CkMailMan_Dispose(mailman);
        CkEmail_Dispose(email);
        return;
    }

    //  The src attribute for the image tag is set to the contentIdStarfish:
    sbHtml = CkStringBuilder_Create();
    CkStringBuilder_Append(sbHtml,"<html><body><p>This is an HTML email with an embedded image.</p>");
    CkStringBuilder_Append(sbHtml,"<p><img src=\"cid:CONTENT_ID_STARFISH\" /></p></body></html>");
    numReplacements = CkStringBuilder_Replace(sbHtml,"CONTENT_ID_STARFISH",contentIdStarfish);

    CkEmail_SetHtmlBody(email,CkStringBuilder_getAsString(sbHtml));

    success = CkMailMan_SendEmail(mailman,email);
    if (success != TRUE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
    }
    else {
        printf("Mail Sent!\n");
    }



    CkFileAccess_Dispose(fac);
    CkByteData_Dispose(imageBytes);
    CkMailMan_Dispose(mailman);
    CkEmail_Dispose(email);
    CkStringBuilder_Dispose(sbHtml);

    }

 

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