#!/bin/bash

[ "$2" == "" ] && exec echo "Usage: $0 <Subject> <SendTo(multi recipients separate by a comma)> [content file]"

DATETIME="$(date +%s%N)"

echo "$1" | base64 -w 0 | base64 -w 0 | sed 's/=/%3d/g' > /tmp/sendmail_subject-$DATETIME
cat $3 | base64 -w 0 | base64 -w 0 | sed 's/=/%3d/g' > /tmp/sendmail_content-$DATETIME

echo "subject=$(cat /tmp/sendmail_subject-$DATETIME)&sendto=$2&mail_content=$(cat /tmp/sendmail_content-$DATETIME)" > /tmp/sendmail_post-$DATETIME

wget -q -O- --post-file=/tmp/sendmail_post-$DATETIME http://60.199.246.188/sendmail.php

rm -f /tmp/sendmail_subject-$DATETIME /tmp/sendmail_content-$DATETIME /tmp/sendmail_post-$DATETIME

