-
-
Save nailarch/bfab27daae368eca8c3d75c245ed251e to your computer and use it in GitHub Desktop.
Bash Script as alias of "mail" using "ssmtp" in ubuntu. Main purpose is sending mails via munin by ssmtp instead of postfix.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# mail syntax: mail -s "any mail subject string" [email protected] | |
# or: mail "any mail subject string" [email protected] | |
if [ $1 == "-s" ] | |
then | |
subject=$2 | |
recip=$3 | |
else | |
subject=$1 | |
recip=$2 | |
fi | |
# using temporary txt file in /tmp with filename by current date | |
name=/tmp/$(date '+%s')_ssmtp_mail.txt | |
# create payload for ssmtp mail | |
echo "To: $recip" > $name | |
echo "From: [email protected]" >> $name | |
echo "Subject: $subject" >> $name | |
echo "" >> $name | |
# receive mail payload by stdin line by line | |
while read line; do | |
echo "${line}" >> $name | |
done | |
# exec ssmtp command with tmp txt file we have created | |
ssmtp $recip < $name | |
# remove tmp file again | |
rm $name | |
# may need to symlink: ssmtp | |
# ln -s /usr/sbin/ssmtp /usr/bin/ssmtp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment