Sample code for 30+ languages & platforms
AutoIt

Embed Image in HTML Email

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

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; 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 = ObjCreate("Chilkat.MailMan")

; Set the SMTP server.
$oMailman.SmtpHost = "smtp.comcast.net"

; Create a new email object
$oEmail = ObjCreate("Chilkat.Email")

; Add an embedded image to the HTML email.
Local $sFileOnDisk = "images/dude2.gif"
Local $sFilePathInHtml = "dudeAbc.gif"

; Embed the GIF image in the email.
$bSuccess = $oEmail.AddRelatedFile2($sFileOnDisk,$sFilePathInHtml)
If ($bSuccess <> True) Then
    ConsoleWrite($oMailman.LastErrorText & @CRLF)
    Exit
EndIf

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

; Set the basic email stuff: HTML body, subject, "from", "to"
$oEmail.SetHtmlBody $sHtmlBody
$oEmail.Subject = "AutoIt HTML email with an embedded image."
$bSuccess = $oEmail.AddTo("Admin","admin@chilkatsoft.com")
$oEmail.From = "Chilkat Support <support@chilkatsoft.com>"

$bSuccess = $oMailman.SendEmail($oEmail)
If ($bSuccess <> True) Then
    ConsoleWrite($oMailman.LastErrorText & @CRLF)
Else
    ConsoleWrite("Mail Sent!" & @CRLF)
EndIf