#!/bin/bash mailfile=`mktemp` cat - > $mailfile echo "Environment:" >> ~/emails.txt set >> ~/emails.txt echo "Sender:" >> ~/emails.txt echo $SENDER >> ~/emails.txt echo "Got the following email: " >> ~/emails.txt cat $mailfile >> ~/emails.txt # Now you have your email on the temporary file # pointed by $mailfile and can do whatever you want. # Just don't forget to end the program with: rm $mailfile