VBScript Requires Chilkat v11.0.0+
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set email = CreateObject("Chilkat.Email")
success = email.LoadEml("text-and-html.eml")
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
set data = CreateObject("Chilkat.BinData")
success = data.AppendString("Time,Activity" & vbCrLf & "09:00,Welcome" & vbCrLf & "10:00,Field session" & vbCrLf,"utf-8")
If (success <> 1) Then
outFile.WriteLine("Failed: data.AppendString.")
WScript.Quit
End If
success = email.AddAttachmentBd("agenda.csv",data,"text/csv")
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
' AddRelatedBd returns the identifier that must appear after cid: in the HTML.
set image = CreateObject("Chilkat.BinData")
success = image.AppendEncoded("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAASUlEQVR4nGMQK/ImBv3//x/CYCBSNQkaIKqJ1YCmGkUDsigu1egakOWwqsaiAaICl2p0P8DV4VKNxdP4VWMPJTyqiY04sZGuAQBhyhp6A/ap2AAAAABJRU5ErkJggg==","base64")
If (success <> 1) Then
outFile.WriteLine("Failed: image.AppendEncoded.")
WScript.Quit
End If
cid = email.AddRelatedBd("confirmed.png",image)
If (email.LastMethodSuccess <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
set html = CreateObject("Chilkat.StringBuilder")
success = html.Append("<p><img alt='Confirmed' src=""cid:")
success = html.Append(cid)
success = html.Append("""></p>")
success = html.Append(email.GetHtmlBody())
success = email.AddHtmlAlternativeBody(html.GetAsString())
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
success = email.SaveEml("with-attachments.eml")
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Saved with-attachments.eml.")
outFile.Close