Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
// 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.
loMime = createobject("CkMime")
llSuccess = loMime.NewMultipartMixed()
if (llSuccess = .F.) then
? loMime.LastErrorText
release loMime
return
endif
// A message body part.
loBodyPart = createobject("CkMime")
llSuccess = loBodyPart.SetBodyFromPlainText("Please see the attached files.")
if (llSuccess = .F.) then
? loBodyPart.LastErrorText
release loMime
release loBodyPart
return
endif
llSuccess = loMime.AppendPart(loBodyPart)
if (llSuccess = .F.) then
? loMime.LastErrorText
release loMime
release loBodyPart
return
endif
// Attach files directly.
llSuccess = loMime.AppendPartFromFile("qa_data/report.pdf")
if (llSuccess = .F.) then
? loMime.LastErrorText
release loMime
release loBodyPart
return
endif
llSuccess = loMime.AppendPartFromFile("qa_data/photo.jpg")
if (llSuccess = .F.) then
? loMime.LastErrorText
release loMime
release loBodyPart
return
endif
? "Number of parts: " + str(loMime.NumParts)
release loMime
release loBodyPart