VBScript
VBScript
Attach a File to a Multipart MIME Entity
See more MIME Examples
Demonstrates the Chilkat Mime.AppendPartFromFile method, which reads a local file, creates an attachment part, and appends it. The only argument is the file path; the content headers are chosen from the filename extension.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: This is the one-call way to add an attachment: Chilkat reads the file, infers its
Content-Type from the extension, base64-encodes binary content, and appends it as a child part — typically inside a multipart/mixed. It is the building block behind adding attachments to an email, saving you from constructing the part and setting its headers by hand.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
' Demonstrates the Mime.AppendPartFromFile method, which reads a local file, creates an attachment
' part, and appends it. The only argument is the file path; the content headers are chosen from
' the filename extension.
set mime = CreateObject("Chilkat.Mime")
success = mime.NewMultipartMixed()
If (success = 0) Then
outFile.WriteLine(mime.LastErrorText)
WScript.Quit
End If
' A message body part.
set bodyPart = CreateObject("Chilkat.Mime")
success = bodyPart.SetBodyFromPlainText("Please see the attached files.")
If (success = 0) Then
outFile.WriteLine(bodyPart.LastErrorText)
WScript.Quit
End If
success = mime.AppendPart(bodyPart)
If (success = 0) Then
outFile.WriteLine(mime.LastErrorText)
WScript.Quit
End If
' Attach files directly.
success = mime.AppendPartFromFile("qa_data/report.pdf")
If (success = 0) Then
outFile.WriteLine(mime.LastErrorText)
WScript.Quit
End If
success = mime.AppendPartFromFile("qa_data/photo.jpg")
If (success = 0) Then
outFile.WriteLine(mime.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Number of parts: " & mime.NumParts)
outFile.Close