The following is an example of a network client written in korn shell to send a multi-part MIME message to an SMTP mail server.



#!/usr/bin/ksh93
################################################################

IPADDR="209.247.163.18"
REPLYTO="dfrench@mtxia.com"
MAILADDR="sombody@somewhere.com"
SUBJECT="This isa some kinda message"

exec 3>&-
exec 3>/dev/tcp/${IPADDR}/25

print -u3 "HELO ${REPLYTO#*@}"; sleep 1
print -u3 "MAIL FROM: ${REPLYTO}"; sleep 1
print -u3 "RCPT TO: ${MAILADDR}"; sleep 1

print -u3 "DATA
Subject: ${SUBJECT}
To: ${MAILADDR}
From: ${REPLYTO}
Reply-to: ${REPLYTO}
Mime-Version: 1.0
Content-Type: Multipart/Mixed; boundary=foo

--foo
Content-Type: text/plain;charset=\"ISO-8859-1\"

"
sleep 1

cat "textfile.txt" >&3

print -u3 '\n\n--foo
Content-Type: text/plain;charset="ISO-8859-1"
Content-Disposition: attachement;filename="secondtext.txt"

'
sleep 1

cat secondtext.txt >&3

print -u3 '\n\n--foo
Content-Type: application/x-msword;name="mswordfile.doc"
Content-Transfer-Encoding: base64
Content-Disposition: attachement;filename="mswordfile.doc"

'
sleep 1

perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' < ../mswordfile.doc >&3
sleep 1

print -u3 '\n\n.'; sleep 1
print -u3 'QUIT'; sleep 1

exec 3>&-