delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/05/14/12:54:41

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <F76C9B2DA2FC4C4CA0A18E288BBCBCF70821790D@nihexchange24.nih.gov>
From: "Buchbinder, Barry (NIH/NIAID)" <BBuchbinder AT niaid DOT nih DOT gov>
To: "'Robert Pollard'" <rpollard AT apple DOT com>, cygwin AT sources DOT redhat DOT com
Subject: RE: Command line email clients
Date: Fri, 14 May 2004 12:54:21 -0400
MIME-Version: 1.0
X-IsSubscribed: yes
Note-from-DJ: This may be spam

------_=_NextPart_000_01C439D4.1A639D84
Content-Type: text/plain

I send email from a scripts using ssmtp, but one needs to construct the
entire message, headers and all.  Earlier I had tried mutt; I don't remember
why I switched, but it may have had something to do with sending MIME.

For your reference (and perhaps your amusement), I've attached the script
that I use to format the message to ssmtp.  It is not totally generic, so
you'll have to make changes and test.

-----Original Message-----
From: Robert Pollard [mailto:rpollard AT apple DOT com] 
Sent: Friday, May 14, 2004 12:08 PM
To: cygwin AT sources DOT redhat DOT com
Subject: Command line email clients

Hi,

I need to automate email notifications from a shell script.  I also 
need to be able to set up the email servers for sending mail through a 
shell script.  Which ever email client I use, I need to automate the 
process of setting up and sending mail.

I have looked at Pine and tried to find information on ssmtp but can't 
locate any information on it.  Pine seems a bit much for what I need.  
I would like to be able to just send email and not have the overhead of 
Pine.  Is there documentation on ssmtp that will show me how to setup a 
smtp server and send an email to it?

Thanks,

Robert Pollard


------_=_NextPart_000_01C439D4.1A639D84
Content-Type: application/octet-stream;
	name="sendmail.sh"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="sendmail.sh"

#!/bin/sh
if test $# =3D 0
then
	$0 --help
	exit 1
fi
if test -z "${IC}"
then
	IC=3D'NIAID'
fi
if test \( -z "${BWareEMail}" \) -o \( -z "${OnLAN}" \)
then
	. envars.sh
fi
CmdLine=3D"$*"

ADDRESSes=3D''
CCs=3D''
SUBJECT=3D''
TEXT=3D''
HTML=3D''
BASE64=3D''
RETURN=3D''

while test ! $# =3D 0
do
	case $1 in
		-a)     # $2 =3D email
			while test ! -z $(echo $2 | \
				grep -e '@')
			do
				ADDRESSes=3D"${ADDRESSes} $2"
				shift
			done
			ADDRESSes=3D"$(echo ${ADDRESSes} | \
				sed -e 's/^  *//')"
			;;
		-c)     # $2 =3D email
			while test ! -z $(echo $2 | \
				grep -e '@')
			do
				CCs=3D"${CCs} $2"
				shift
			done
			CCs=3D"$(echo ${CCs} | \
				sed -e 's/^  *//')"
			;;
		-s)     SUBJECT=3D"$2"     # $2 =3D string
			shift
			;;
		-t)     TEXT=3D"$2"        # $2 =3D filename
			shift
			;;
		-h)     HTML=3D"$2"        # $2 =3D filename
			shift
			;;
		-b)     BASE64=3D"$2"      # $2 =3D filename
			shift
			;;
		-r)     RETURN=3D'Y'
			;;
		--help) echo 'usage: sendmail.sh -a ADDRESSes [ -c CCs ] [ -s SUBJECT_STR=
ING ] [ -r ]
	[ -t TEXT_BODY_FILE ] [ -h HTML_BODY_FILE ] [ -b ATTACHMENTs ]
	=1B[1;34m-r =3D return receipt requested, currently sent to
		=1B[1;36m'${BWareEMail}'=1B[0;37m
	=1B[1;34mThe order of the options does not matter.=1B[0;37m'
			exit 0
			;;
		*)      echo "=1B[1;31merror=1B[0;37m: option =1B[1m$1=1B[0m unknown"
			$0 --help
			exit 1
			;;
	esac
	shift
done

{
	echo "From: ${BWareEMail}"
	for to in ${ADDRESSes}
	do
		echo "To: ${to}"
	done
	for cc in ${CCs}
	do
		echo "CC: ${cc}"
	done
	echo "Reply-To: ${BWareEMail}"
	if test "${RETURN}" =3D 'Y'
	then
		echo "Disposition-Notification-To: ${BWareEMail}"
		echo "Return-Receipt-To: ${BWareEMail}"
	fi
	echo "Subject: ${SUBJECT}
Date: $(date -R)"'
Sensitivity: Company-Confidential
MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary=3D"----_=3D_NextPart_000"

This message is in MIME format.  Since your mail reader does not
understand this format, some or all of this message may not be legible.

------_=3D_NextPart_000
Content-Type: multipart/alternative;
        boundary=3D"----_=3D_NextPart_001"
'
	if test ! -z "${TEXT}"
	then
		echo '
------_=3D_NextPart_001
Content-Type: text/plain;
       charset=3D"iso-8859-1"
'
		cat "${TEXT}"
	fi
	if test ! -z "${HTML}"
	then
		echo '
------_=3D_NextPart_001
Content-Type: text/html;
       charset=3D"iso-8859-1"
'
		cat "${HTML}"
	fi
	if test ! -z "${BASE64}"
	then
		for FILE in ${BASE64}
		do
			NAME=3D$(basename ${FILE})
			echo '
------_=3D_NextPart_001
Content-Type: application/octet-stream;
        name=3D"'${BASE64}'"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
        filename=3D"'${NAME}'"
'
			uuencode -m ${FILE} ${NAME} | \
				sed	-e '1d' \
					-e '$d'
		done
	fi
	echo '
------_=3D_NextPart_000--
'
} \
	> sendmail.tmp
if test ! "${NOMAIL}" =3D 'NOMAIL'
then
	if test "${NOMAIL}" =3D 'LESS'
	then
		less sendmail.tmp
	else
		if test "${OnLAN}" =3D 'Y'
		then
			LogFile=3D$(date +'log/sendmail.%y%m%d-%H%M%S')
			date > ${LogFile}
			echo "
To:      ${ADDRESSes}
CC:      ${CCs}
Subject: ${SUBJECT}
text:    ${TEXT}
html:    ${HTML}
attach:  ${BASE64}
" \
				> ${LogFile}
			{
				echo ${ADDRESSes} | \
					sed	-e 's/ /;  /g' \
						-e 's/^/         /' | \
					fmt -w 68 | \
					sed	-e '1s/^   /To:/' \
						-e 's/;/=1B[0;37;45m;=1B[1;36;45m/g'
				echo ${CCs} | \
					sed	-e 's/ /; /g' \
						-e 's/;$//' \
						-e 's/^/         /' | \
					fmt -w 68 | \
					sed	-e '1s/^   /To:/' \
						-e 's/;/=1B[0;37;45m;=1B[1;36;45m/g'
				echo "Subject: ${SUBJECT}"
				echo "text:    ${TEXT}"
				echo "html:    ${HTML}"
				echo "attach:  ${BASE64}"
			} | \
				sed	-e 's/^/=1B[0;45m=1B[K /' \
					-e 's/$/=1B[0;45m=1B[K=1B[0;37;40m/' \
					-e '/         /s/ /=1B[1;36m /' \
					-e 's/:/:=1B[1;36m/'
			/usr/sbin/ssmtp -t -v < sendmail.tmp 2>&1 | \
				tee -a ${LogFile} | \
				grep	-e '\[->\] To:' \
					-e '\[->\] CC:' \
					-e '\[->\] Subject:' \
					-e '\[->\] Date:' \
					-e 'Reply-To:' \
					-e 'Disposition-Notification-To:' \
					-e 'Return-Receipt-To:' \
					-e '\[<-\] 2' | \
				sed -e 's/^.*$/	=1B[1;34m=1B[K&=1B[0;37m=1B[K/'
			echo "=1B[0;30;45m=1B[K ssmtp is finished (called by =1B[36m$(pwd)/$(bas=
ename $0)=1B[30;45m)=1B[0;37;40m"
			echo >> ${LogFile}
			date >> ${LogFile}
			unset LogFile
		fi
	fi

fi
rm sendmail.tmp
unset ADDRESSes CCs SUBJECT TEXT HTML BASE64 RETURN to cc CmdLine


------_=_NextPart_000_01C439D4.1A639D84
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------_=_NextPart_000_01C439D4.1A639D84--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019