AutoIt Requires Chilkat v11.0.0+
AutoIt
Add an attachment and an inline image
See more Email Object Examples
Add a file attachment from memory and embed an image in the HTML body using its Content-ID. Start with any email that has an HTML body, or use text-and-html.eml from the preceding example. Save the result as with-attachments.eml.
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$oEmail = ObjCreate("Chilkat.Email")
$bSuccess = $oEmail.LoadEml("text-and-html.eml")
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$oData = ObjCreate("Chilkat.BinData")
$bSuccess = $oData.AppendString("Time,Activity" & @CRLF & "09:00,Welcome" & @CRLF & "10:00,Field session" & @CRLF,"utf-8")
If ($bSuccess <> True) Then
ConsoleWrite("Failed: data.AppendString." & @CRLF)
Exit
EndIf
$bSuccess = $oEmail.AddAttachmentBd("agenda.csv",$oData,"text/csv")
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
; AddRelatedBd returns the identifier that must appear after cid: in the HTML.
$oImage = ObjCreate("Chilkat.BinData")
$bSuccess = $oImage.AppendEncoded("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAASUlEQVR4nGMQK/ImBv3//x/CYCBSNQkaIKqJ1YCmGkUDsigu1egakOWwqsaiAaICl2p0P8DV4VKNxdP4VWMPJTyqiY04sZGuAQBhyhp6A/ap2AAAAABJRU5ErkJggg==","base64")
If ($bSuccess <> True) Then
ConsoleWrite("Failed: image.AppendEncoded." & @CRLF)
Exit
EndIf
Local $sCid = $oEmail.AddRelatedBd("confirmed.png",$oImage)
If ($oEmail.LastMethodSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$oHtml = ObjCreate("Chilkat.StringBuilder")
$oHtml.Append("<p><img alt='Confirmed' src=""cid:")
$oHtml.Append($sCid)
$oHtml.Append("""></p>")
$oHtml.Append($oEmail.GetHtmlBody())
$bSuccess = $oEmail.AddHtmlAlternativeBody($oHtml.GetAsString())
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oEmail.SaveEml("with-attachments.eml")
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Saved with-attachments.eml." & @CRLF)