auto email zip attachment with Command line email tool

The following example explains how to create a zip archive of files and send the zip file as an email attachment using Febooti Command line email tool for Windows. A zip archive is a file which contains other files and documents in a compressed format. Zip files are very useful for email attachments as they only need be attached once rather than having to attach many separate files. Zip files also preserve subfolder structure and allow segmentation, which means that archive can be split into smaller parts if required. This is useful in situations where the mail server does not allow sending attachments bigger than a certain size.

SOLUTION:

There are many good zip utilities around. The documentation for a specific utility should be referenced for command line syntax and parameters. This example assumes the use of a simple imaginary zip tool called myzip.

@echo off

rem Archive files and folders / directories...
rem -a : archive files and folders.
rem -r : recursively add files and further subdirectories.
rem c:\work\ : pathname to archive.
rem archive.zip : archive to be created.

myzip -a -r c:\work\ archive.zip

rem Send email with zip attachment...
febootimail -SERVER e-mail.server.com -FROM me@my-home-server.com -TO me@my-work-server.com -SUBJECT "Data attached as zip archive" -MSG The attached ZIP file is sample report. Attachment have been emailed using Febooti Command line e-mail for Windows. A printout is required for archiving. -ATTACH archive.zip

1: In order to send email automatically, zip archive must be created first. This is done by supplying the desired zip utility with command line parameters in the batch file. Every zip utility is different in implementation, thus the user documentation should be referenced for help. In the sample batch file it is assumed that myzip utility will use four parameters. These are:

  • -a : To add a file or directory.
  • -r : To recursively add files and further subdirectories in the specified directory.
  • The pathname of directory which contains the source files, i.e., c:\work\.
  • A filename for the archive to be created, i.e., archive.zip.

Thus in this example myzip will add the entire contents (i.e., subdirectories and files) of the folder C:\work\ to the archive.zip file.

2: The second task is to call command line mail tool to send email automatically. The email command line structure is defined in the example file. The parameters are explained below:

  • -SERVER : This is the name of the outgoing mail server in standard URL format or as an IP address.
  • -FROM : This is the email address of the sender. In the cited example the user is sending an email from their home address to their work address.
  • -TO : Specifies the recipient email address.
  • -SUBJECT : A good subject line makes understanding the contents of the email easier for the reader.
  • -MSG : The contents of the message body in plain text format.
  • -ATTACH : Allows files to be attached to the email for sending. The filename must be enclosed in double quotes if it contains spaces.

Please do not hesitate to contact our support department with any possible further questions or to solve practical issues connected with Command line email integration.

Copyright © 2001-2011 Febooti Software. All rights reserved. Last updated: November 03, 2008