wiki.getshifting.com

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


aixmailwithencryptedattachments

Script: AIX Mail With Encrypted Attachments

Summary: ALthough AIX is by now on version 7.3 I find these old pages so fascinating I decided to keep them. On this page I'll show you a script to send out an email with attachments that need to be encrypted. This page is for AIX 5.3 and AIX 6.1.
Date: Between 2010-2013
Refactor: 21 December 2024: Checked formatting.

Introduction

This is a script that can be used to send a couple of predefined files as encrypted attachments. Very useful for sending secure reports. Also note that the password needs to be sent separately to the receiver.

#!/bin/bash
########################################################################################################################
# Author : Sjoerd Hooft
# Date Initial Version: 16 feb 2011
# Comments: sjoerd_@_getshifting_com
#
# Description:
# This is a sample script to send encrypted attachments over mail
#
# Recommendations:
# The script is designed for a 120 column terminal.
# The running user must be able to do a passwordless sudo to root.
#
# Changes:
# Please comment on your changes to the script (your name and email address, line number, description):
########################################################################################################################
 
# Script Variables
BASEDIR=`dirname $0`
MAILFROM=sjoerd_getshifting_com
MAILTO=sjoerd_getshifting_com
TEMPLATEDIR=$BASEDIR\templates
 
# Function to send mail
# Args:
# 1: FROM_ADDRESS
# 2: TO_ADDRESS
# 3: Subject
# 4: Filename of contents email
# 5: Space seperated list of files to attach
mailAttach () {
  (cat ${4}; for k in ${5}; do uuencode $k ${k##*/}; done) | \
      mailx -r ${1} -s "${3}" "${2}"
}
 
# Start Script
echo "Compressing and securing files before transmission..."
echo
echo "Enter zip-file password when a password is requested, this password should be sent to email receiver ($TOMAIL) via SMS"
(cd /tmp; \
  zip -e secured-file-`date +%d%m%Y`.zip \
    file1.xls \
    file2.xls \
    file3.xls \
    file4.xls; \
    cd -)
 
echo "Sending reports to $MAILTO by mail..."
fn_sendmail ${MAILFROM} \
        ${MAILTO} \
        "Email with encrypted attachments `date +%B` -- mail 1" \
        ${TEMPLATEDIR}/mailtext.txt \
        /tmp/secured-file-`date +%d%m%Y`.zip
 
echo "Finished sending mail"
exit

Note that you need a template which will be the body of the mail, it could look something like this:

Dear Sir/Madam,

Here are the encrypted files you requested.

Kind regards,
Sjoerd Hooft
aixmailwithencryptedattachments.txt · Last modified: by 127.0.0.1