Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to help send HTML email via Mail.app' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to help send HTML email via Mail.app
Authored by: bluehz on Mar 08, '05 12:14:37PM
Here's a quick script I whippped up for sending html+plain text email from terminal. I believe it does require a working sendmail/postfix. Anyway - thought I would post for others, it could of course be vastly improved.
#!/bin/sh

#
# USER DEFINED VARIABLES
#

name="Your name here"                 # real name
fromaddr="name@server.com ($name)"  # e-mail address  
replyaddr="name@server.com ($name)"         # reply to e-mail address

# var
boundary=`openssl rand -base64 12`

#
# MAIN
#

# Usage

if [ $# -lt 3 ] ; then
  echo <<EOF "Usage: $(basename $0) subject address plaintxt htmltxt

   Where plaintxt points to a plain text file
   and htmltxt points to an html formatted file"
EOF
  exit 1
fi

# Send email

( echo "From: $fromaddr"
  echo "Subject: $1"
  echo "To: $2"
  echo "Reply-To: $replyaddr"
  echo "Return-Path: $fromaddr"
  echo "MIME-Version: 1.0"
  echo "Content-Type: multipart/alternative; boundary=$boundary"
  # add as many X-Headers as you desire below
  echo "X-Priority: 3"
  echo "X-Mailer: MailX"
  echo "X-System: Mac OS X"
  echo ""

# Plain Text Content
echo <<EOF "This is a multi-part message in MIME format.
If you see this message, then you are not using a
MIME compliant mail reader.

--$boundary
Content-Type: text/plain;
	charset=\"US-ASCII\"
Content-Transfer-Encoding: 7bit"
EOF
if [ $4 ]; then
cat $3
fi
echo ""

# HTML Text Content
echo <<EOF "--$boundary
Content-Type: text/html;
	charset=\"US-ASCII\"
Content-Transfer-Encoding: quoted-printable"
EOF
if [ $4 ]; then
cat $4
else
cat $3
fi

echo ""
echo "--$boundary--"
  
) | sendmail -t

exit 0


[ Reply to This | # ]