Sample code for 30+ languages & platforms
Classic ASP

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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
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.

set email = Server.CreateObject("Chilkat.Email")
email.Subject = "Zip the attachments"

success = email.AddStringAttachment("a.txt","first attachment")
success = email.AddStringAttachment("b.txt","second attachment")
Response.Write "<pre>" & Server.HTMLEncode( "NumAttachments before = " & email.NumAttachments) & "</pre>"

'  Replace all attachments with a single Zip attachment named "files.zip".
success = email.ZipAttachments("files.zip")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "NumAttachments after = " & email.NumAttachments) & "</pre>"

%>
</body>
</html>