Xbase++
Xbase++
Embed Image in HTML Email
Demonstrates how to create and send an HTML email with an embedded image.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oMailman
LOCAL oEmail
LOCAL cFileOnDisk
LOCAL cFilePathInHtml
LOCAL cHtmlBody
nSuccess := 0
// 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.
oMailman := CreateObject("Chilkat.MailMan")
// Set the SMTP server.
oMailman:SmtpHost := "smtp.comcast.net"
// Create a new email object
oEmail := CreateObject("Chilkat.Email")
// Add an embedded image to the HTML email.
cFileOnDisk := "images/dude2.gif"
cFilePathInHtml := "dudeAbc.gif"
// Embed the GIF image in the email.
nSuccess := oEmail:AddRelatedFile2(cFileOnDisk, cFilePathInHtml)
IF (nSuccess != 1)
? oMailman:LastErrorText
oMailman:destroy()
oEmail:destroy()
RETURN
ENDIF
// The src attribute for the image tag is set to the filePathInHtml:
cHtmlBody := '<html><body>Embedded Image:<br><img src="dudeAbc.gif"></body></html>'
// Set the basic email stuff: HTML body, subject, "from", "to";
oEmail:SetHtmlBody(cHtmlBody)
oEmail:Subject := "Xbase++ HTML email with an embedded image."
nSuccess := oEmail:AddTo("Admin", "admin@chilkatsoft.com")
oEmail:From := "Chilkat Support <support@chilkatsoft.com>"
nSuccess := oMailman:SendEmail(oEmail)
IF (nSuccess != 1)
? oMailman:LastErrorText
ELSE
? "Mail Sent!"
ENDIF
oMailman:destroy()
oEmail:destroy()