Sample code for 30+ languages & platforms
AutoIt

Send HTML Email with Embedded Image Loaded from Memory

See more SMTP Examples

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

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.

;  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.
$oFac = ObjCreate("Chilkat.FileAccess")
Local $oImageBytes
$oImageBytes = $oFac.ReadEntireFile("qa_data/jpg/starfish.jpg")

;  The mailman object is used for sending and receiving email.
$oMailman = ObjCreate("Chilkat.MailMan")

;  Use your SMTP server hostname.  This example uses office365, but it could be any SMTP server..
$oMailman.SmtpHost = "outlook.office365.com"
$oMailman.SmtpPort = 587
$oMailman.StartTLS = True

;  Set the SMTP login/password
$oMailman.SmtpUsername = "OFFICE365-SMTP-LOGIN"
$oMailman.SmtpPassword = "OFFICE365-SMTP-PASSWORD"

;  Create a new email object
$oEmail = ObjCreate("Chilkat.Email")
$oEmail.Subject = "HTML Email with Image Loaded from In-Memory Bytes"
$oEmail.From = "Chilkat Support <my-office365-user@mydomain.com>"
$oEmail.AddTo("Chilkat Support","support@chilkatsoft.com")

Local $sContentIdStarfish = $oEmail.AddRelatedData("starfish.jpg",$oImageBytes)
If ($oEmail.LastMethodSuccess <> True) Then
    ConsoleWrite($oEmail.LastErrorText & @CRLF)
    Exit
EndIf

;  The src attribute for the image tag is set to the contentIdStarfish:
$oSbHtml = ObjCreate("Chilkat.StringBuilder")
$oSbHtml.Append("<html><body><p>This is an HTML email with an embedded image.</p>")
$oSbHtml.Append("<p><img src=""cid:CONTENT_ID_STARFISH"" /></p></body></html>")
Local $iNumReplacements = $oSbHtml.Replace("CONTENT_ID_STARFISH",$sContentIdStarfish)

$oEmail.SetHtmlBody $oSbHtml.GetAsString()

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