Technical article 125481

How can I email attachments from UNIX to a Mail Client?

OpenServer 6.0.0OpenServer 5.0.6OpenServer 5.0.7UnixWare 7.0.0UnixWare 7.0.1UnixWare 7.1.0UnixWare 7.1.1UnixWare 7.1.2UnixWare 7.1.3UnixWare 7.1.4Open UNIX 8

Written · Last revised

Problem

I need to email with an attachment, such as a TXT file,
a comma separated file or Microsoft Word Document, to a
Windows mail client such as Outlook, or a non-Windows mail
client, an attachment  How can I achieve this so that when
the mail arrives on the Mail Client you just have to double
click on the icon and it will open the appropriate application
relevant to the application.  For example, if the attachment
ended with a .txt extension, NOTEPAD.EXE is used, etc.

Solution

For SCO UnixWare7 Only:
----------------------
- Method if Mail is already configured...

On the UnixWare7 server you will need to have configured Sendmail using "scoadmin mail" to configure your mail system appropriately.

For example, Mail Delivery Channels -> Badhost -> Forward all Channel Mail to -> "mysmarthost"

Use the following script to email any attachment type.

The script can be improved but this demonstrates proof of concept:

----------------------------------------------------------
#
exec >> /tmp/mail.log 2>&1
SUBJECT=$1
TEXT=$2
TO=$3
FROM=$4
REPORT=/tmp/report.$$
cat $TEXT > $REPORT
echo "
Here is the mail
Please click on the attachment
~**
$REPORT
1
application/octet-stream; name=$TEXT
$TEXT"|mail -~ -s "$SUBJECT" "$TO"
----------------------------------------------------------

Call this script "mailit" and make it executable using the command:

# chmod 755 mailit
Run the command in the format:
# ./mailit "Test Subject" hello.txt user@domain
Where "hello.txt" could be a simple text file containing
the words "hello world".  Rename the file to "hello.csv"
or "hello.doc" and email it to ensure that the
appropriate application icon is associated with the file
when it arrives in the Mail Client.

This will only function on SCO UnixWare7 which supports the "-~" option.

- Method if no Mail is already configured...

Here is a script which automates the sending of an email with an
attachment to a recipient.  Within in the script you will need to
configure "mysmarthost", ie. where the email needs to go to, your
email address (me@mydomain.com) and the recipient
(you@yourdomain.com).  The file send-test.tar needs to be created as
well as a text file called "email.txt" containing "Hello World".
----- cut here -----
#
# send-mail.sh
#
#
# Script to bodge an email and an attachment through telnet 25 port.
# Uses uuencode to convert a binary file for transmission
#
# Mail server name or IP address
SEND_MAIL_SERVER=mysmarthost export SEND_MAIL_SERVER
#
# The person to mail from
SEND_MAIL_FROM=me@mydomain.com export SEND_MAIL_FROM
#
# The person to mail to
SEND_MAIL_TO=you@yourdomain.com export SEND_MAIL_TO
#
# The subject line
SEND_MAIL_SUBJECT="Attachment Test" export SEND_MAIL_SUBJECT
#
# File containing email body text
SEND_MAIL_TEXT_FILE=email.txt export SEND_MAIL_TEXT_FILE
#
# The file to attach
SEND_MAIL_ATTACHMENT=send-test.tar export SEND_MAIL_ATTACHMENT
#
# MIME Boundary marker
SEND_MAIL_BOUNDARY="=SEND=eMaIl=BoUnDaRy=" export SEND_MAIL_BOUNDARY
#
# Attachment CONTENT type
SEND_MAIL_CONTENT_TYPE="application/octet-stream" export SEND_MAIL_CONTENT_TYPE
#
# CONTENT type extension
SEND_MAIL_CONTENT_TYPE_EXT=".uu" export SEND_MAIL_CONTENT_TYPE_EXT
#
# Attachment encoding
SEND_MAIL_ENCODING="8bit" export SEND_MAIL_ENCODING
#
# Attachment encoding program
SEND_MAIL_ENCODER=/usr/bin/uuencode export SEND_MAIL_ENCODER
#
# File to log mail server messages and errors
SEND_MAIL_LOG=send-mail.log export SEND_MAIL_LOG
#
# Clear the log file - comment out to append all messages
> $SEND_MAIL_LOG
#
(
#
# Need to sleep bits to allow email server to reply
sleep 5
# Initiate email
echo "HELO"
sleep 1
echo "MAIL FROM:<$SEND_MAIL_FROM>"
sleep 1
echo "RCPT TO:<$SEND_MAIL_TO>"
sleep 1
echo DATA
sleep 1
echo "From: <$SEND_MAIL_FROM>"
echo "To: <$SEND_MAIL_TO>"
echo "Content-type: multipart/mixed; boundary=$SEND_MAIL_BOUNDARY"
echo "Subject: $SEND_MAIL_SUBJECT"
echo ""
echo "--$SEND_MAIL_BOUNDARY"
echo "Content-type: text/plain; charset=iso-8859-1"
echo "Content-transfer-encoding: 8bit"
echo ""
if [ -f $SEND_MAIL_TEXT_FILE ]; then
 cat $SEND_MAIL_TEXT_FILE
else
 echo "Could not open the file '$SEND_MAIL_TEXT_FILE'"
fi
echo ""
echo "--$SEND_MAIL_BOUNDARY"
echo "Content-type: SEND_MAIL_CONTENT_TYPE; name=$SEND_MAIL_ATTACHMENT$SEND_MAIL_CONTENT_TYPE_EXT"
echo "Content-transfer-encoding: $SEND_MAIL_ENCODING"
echo "Content-Description: $SEND_MAIL_ATTACHMENT$SEND_MAIL_CONTENT_TYPE_EXT"
echo '"Content-Disposition: attachment; filename="'$SEND_MAIL_ATTACHMENT$SEND_MAIL_CONTENT_TYPE_EXT'"'
echo ""
$SEND_MAIL_ENCODER $SEND_MAIL_ATTACHMENT $SEND_MAIL_ATTACHMENT
echo "--$SEND_MAIL_BOUNDARY--"
echo ""
sleep 1
echo "."
sleep 1
echo ""
sleep 1
echo "QUIT"
) 2>> $SEND_MAIL_LOG | telnet $SEND_MAIL_SERVER 25 >> $SEND_MAIL_LOG 2>&1
----- end cut here -----
For All SCO Unix:
----------------
Another alternative is to use the mail agent MUTT, which has an (-a)
option for adding attachments.  MUTT will mime-encode your
attachement.  MUTT is available through skunkware.

From the command line you can run:

# mutt -x -a <file to attach> -s <subject> email_addr < mail.body.txt
For UnixWare7:
-------------
ftp://ftp2.sco.com/pub/skunkware/uw7/Packages/mutt-1.2.5.1.pkg
For OpenServer6:
---------------
ftp://ftp2.sco.com/pub/skunkware/osr6/vols/mutt-1.4.2.1iSa-VOLS.cpio
For OpenServer5:
---------------
ftp://ftp2.sco.com/pub/skunkware/osr5/vols/mutt-1.2.5.1-VOLS.tar
ftp://ftp2.sco.com/pub/skunkware/osr5/vols/ncurses-4.2-VOLS.tar

For it to work in an MMDF environment, please change:

sendmail="/usr/lib/mail/execmail"
in the Muttrc file.

See also

mailx(4)

From the Xinuos technical article database, record 125481. Reproduced with permission. The original is at www.sco.com/ta/125481, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.