Skip to content

Instantly share code, notes, and snippets.

@casperbiering
Last active December 8, 2016 17:22
Show Gist options
  • Save casperbiering/dde01a156b1418e7b0f58731b80198cc to your computer and use it in GitHub Desktop.
Save casperbiering/dde01a156b1418e7b0f58731b80198cc to your computer and use it in GitHub Desktop.
#!/bin/bash
TO="user@example.com"
FROM="user@example.com"
SUBJECT="Invalid sending domain on `hostname`"
MESSAGE="The attached mail did not comply with our sender domains on `hostname`."
TMPFILE=$(mktemp)
trap "rm -f $TMPFILE" 0 1 2 3 15
HEADER="To: $TO
From: $FROM
Subject: $SUBJECT
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary=\"_----------=_148120056728766463\"
This is a multi-part message in MIME format.
--_----------=_148120056728766463
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=\"utf-8\"
$MESSAGE
--_----------=_148120056728766463
Content-Disposition: attachment; filename=\"attached.eml\"
Content-Type: message/rfc822; name=\"attached.eml\"
Content-Transfer-Encoding: 8bit
"
FOOTER="
--_----------=_148120056728766463--
"
echo -e "$HEADER" >> $TMPFILE
#cat | base64 -w 60 >> $TMPFILE
cat >> $TMPFILE
echo -e "$FOOTER" >> $TMPFILE
#cat $TMPFILE
/usr/sbin/sendmail -t -f $FROM -F "" < $TMPFILE
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment