Sample code for 30+ languages & platforms
PowerBuilder

Zip an Email's Attachments into One File

See more Email Object Examples

Demonstrates the Chilkat Email.ZipAttachments method, which replaces all of an email's attachments with a single Zip file attachment having the specified filename. The original attachments are removed and packed into the Zip. This example adds two attachments and zips them into one.

Background: Bundling multiple attachments into a single .zip keeps a message tidy, compresses the payload, and works around recipients or gateways that limit the number of attachments. Note that the filename here (files.zip) names the attachment inside the message — it is not a path on disk. The reverse operation is UnzipAttachments.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email

li_Success = 0

//  Demonstrates the ZipAttachments method, which replaces all of an email's attachments
//  with a single Zip file attachment having the specified filename.  The original
//  attachments are removed and packed into the Zip.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.Subject = "Zip the attachments"

loo_Email.AddStringAttachment("a.txt","first attachment")
loo_Email.AddStringAttachment("b.txt","second attachment")
Write-Debug "NumAttachments before = " + string(loo_Email.NumAttachments)

//  Replace all attachments with a single Zip attachment named "files.zip".
li_Success = loo_Email.ZipAttachments("files.zip")
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

Write-Debug "NumAttachments after = " + string(loo_Email.NumAttachments)


destroy loo_Email