Zip and Email Files

This process prompts the user to select multiple files, compresses them into a zip file and mails them to a specified email address.

Display.SelectFile Title:'Please select the file(s) that you want to zip and email.' \
                    InitialDirectory:'' \
                    FileFilter:'' \
                    IsTopMost:False \
                    CheckIfFileExists:True \
                    SelectedFile=> FilesToZipAndMail \
                    ButtonPressed=> ButtonPressed

if ButtonPressed='Open' then
	Folder.GetSpecialFolder SpecialFolder:Folder.SpecialFolder.DesktopDirectory \
                    SpecialFolderPath=> DesktopDirectory 

        Compression.ZipFiles ArchivePath:DesktopDirectory+'\FilesToBeEmailed.zip' \
                    FilesToZip:FilesToZipAndMail  \
                    CompressionLevel:Compression.CompressionLevel.Normal \
                    Password:'' \
                    ArchiveComment:'' \
                    ZipFile=> GeneratedZipFile

	Email.Send SMTPServer:'smtp.example.com'  \
                    Port:25 \
                    EnableSSL:False \
                    SendFrom:'sender@example.com'  \
                    SenderDisplayName:"Sender's Name" \
                    SendTo:'recipient@example.com' \
                    CC:'' \
                    BCC:'' \
                    Subject:'Zipped Files' \
                    Body:'You can find the compressed files attached.' \
                    IsBodyHtml:False \
                    Attachments:GeneratedZipFile

	File.Delete Files: GeneratedZipFile

end

Display.ShowMessage Title:'Process Completed!' \
                    Message:'Process "Zip and Email Files" completed.' \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed

In more detail:


The process prompts the user to select multiple files and checks whether they did. If so, it retrieves the desktop path, compresses the files into a zip file which is saved on the desktop, and mails them to a specified email address. Finally, it deletes the generated zip file.

Step 1: Prompt the User to Select Multiple Files

Use the “Display.SelectFile” action and store the selected files in the “FilesToZipAndMail” output variable.

Display.SelectFile Title:'Please select the file(s) that you want to zip and email.' \
                    InitialDirectory:'' \
                    FileFilter:'' \
                    IsTopMost:False \
                    CheckIfFileExists:True \
                    SelectedFile=> FilesToZipAndMail \
                    ButtonPressed=> ButtonPressed

Use the “Display.SelectFile”action and set the Dialog title and message.

Step 2: Compress the Selected Files

Check whether the user has selected files and, if so, compress them into a zip file.

if ButtonPressed='Open' then
	Folder.GetSpecialFolder SpecialFolder:Folder.SpecialFolder.DesktopDirectory \
                    SpecialFolderPath=> DesktopDirectory 

        Compression.ZipFiles ArchivePath:DesktopDirectory+'\FilesToBeEmailed.zip' \
                    FilesToZip:FilesToZipAndMail  \
                    CompressionLevel:Compression.CompressionLevel.Normal \
                    Password:'' \
                    ArchiveComment:'' \
                    ZipFile=> GeneratedZipFile
  1. Use the “if” statement to check whether the “ButtonPressed” output variable of the previous action is equal to “Open”.
  2. Use the “Folder.GetSpecialFodler” action to retrieve the desktop path, in order to save the compressed files there later.
  3. Use the “Compression.ZipFiles” action to compress the selected files:
    1. Set the “ArchivePath” argument to “DesktopDirectory+ ‘\FilesToBeEmailed.zip’”.
    2. Set the “FilesToZip” argument to “FilesToZipAndMail”, which is the output variable of the “Display.SelectFile” action.
    3. Store the file in the “GeneratedZipFile” output variable.

Step 3: Mail the Zip File

Mail the compressed files to a specified email address and delete the generated zip file after the email is sent.

Email.Send SMTPServer:'smtp.example.com'  \
                    Port:25 \
                    EnableSSL:False \
                    SendFrom:'sender@example.com'  \
                    SenderDisplayName:"Sender's Name" \
                    SendTo:'recipient@example.com' \
                    CC:'' \
                    BCC:'' \
                    Subject:'Zipped Files' \
                    Body:'You can find the compressed files attached.' \
                    IsBodyHtml:False \
                    Attachments:GeneratedZipFile

	File.Delete Files: GeneratedZipFile

end

Display.ShowMessage Title:'Process Completed!' \
                    Message:'Process "Zip and Email Files" completed.' \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed
  1. Use the “Email.Send” action to send an email with the “GeneratedZipFile” as an attachment:
    1. Configure the SMTP Server details, and set the “SendFrom”, “SendTo”, “Subject” and “Body” arguments to the desired values.
    2. Set the “Attachments” argument to “GeneratedZipFile”, which is the output variable of the “Compression.ZipFiles” action.

  2. Use the “File.Delete” action, by setting the “Files” argument to “GeneratedZipFile”.
  3. Close the conditional block, using the “end” statement. In case the user did not select any files, i.e. the “Open” button was not pressed in the “Select File” dialog box, the above actions will not be executed.
  4. Optionally, inform the user when the process is completed, using the “Display.ShowMessage” action.