VBScript Requires Chilkat v11.0.0+
VBScript
Save attachments from a received message
See more Email Object Examples
Use a dedicated output directory for this message. The example lists the declared names and sizes, then saves downloaded attachment bodies. A related image in HTML and an attached email have their own collections.
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("attachments.eml")
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
If (email.NumAttachments = 0) Then
outFile.WriteLine("There are no ordinary file attachments.")
WScript.Quit
End If
i = 0
Do While (i < email.NumAttachments)
outFile.WriteLine(email.GetAttachmentFilename(i) & " " & email.GetAttachmentSize(i) & " bytes")
i = i + 1
Loop
' Use a fresh output folder per message and keep existing files.
email.OverwriteExisting = 0
success = email.SaveAllAttachments("workshop-attachments")
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Saved attachments in workshop-attachments.")
outFile.Close