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

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

 

 

 

(Delphi DLL) Embed Image in HTML Email

Demonstrates how to create and send an HTML email with an embedded image.

Chilkat for Delphi Downloads

Chilkat non-ActiveX DLL for Delphi

Chilkat ActiveX DLL for Delphi

* The examples here use the non-ActiveX DLL.

uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, MailMan, Email;

...

procedure TForm1.Button1Click(Sender: TObject);
var
mailman: HCkMailMan;
success: Boolean;
email: HCkEmail;
fileOnDisk: PWideChar;
filePathInHtml: PWideChar;
htmlBody: PWideChar;

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

//  Any string argument automatically begins the 30-day trial.
success := CkMailMan_UnlockComponent(mailman,'30-day trial');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;

//  Set the SMTP server.
CkMailMan_putSmtpHost(mailman,'smtp.comcast.net');

//  Create a new email object
email := CkEmail_Create();

//  Add an embedded image to the HTML email.
fileOnDisk := 'images/dude2.gif';
filePathInHtml := 'dudeAbc.gif';

//  Embed the GIF image in the email.
success := CkEmail_AddRelatedFile2(email,fileOnDisk,filePathInHtml);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;

//  The src attribute for the image tag is set to the filePathInHtml:
htmlBody := '<html><body>Embedded Image:<br><img src="dudeAbc.gif"></body></html>';

//  Set the basic email stuff: HTML body, subject, "from", "to";
CkEmail_SetHtmlBody(email,htmlBody);
CkEmail_putSubject(email,'Delphi DLL HTML email with an embedded image.');
success := CkEmail_AddTo(email,'Admin','admin@chilkatsoft.com');
CkEmail_putFrom(email,'Chilkat Support <support@chilkatsoft.com>');

success := CkMailMan_SendEmail(mailman,email);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
  end
else
  begin
    Memo1.Lines.Add('Mail Sent!');
  end;

CkMailMan_Dispose(mailman);
CkEmail_Dispose(email);

end;

 

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