Technical article 125337

I want to create a script or use the command line to send an email with an attachment non-interactively, how can I do this?

OpenServer 6.0.0OpenServer 5.0.0OpenServer 5.0.2OpenServer 5.0.4OpenServer 5.0.5OpenServer 5.0.6OpenServer 5.0.7UnixWare 7.0.0UnixWare 7.0.1UnixWare 7.1.0UnixWare 7.1.1UnixWare 7.1.2UnixWare 7.1.3Open UNIX 8

Written · Last revised

Problem

I need the ability to send an email with an attachment
non-interactively.  For example, a script, application or
cron job to email an attached file to another email
address automatically.
How can I do this?

Cause

The standard mail utility on OpenServer and UnixWare cannot attach files to emails.

Another utility must be used.

This article describes how to use the mail utility "mutt" to achieve this.

Mutt is a free skunkware product, does not require a license and is unsupported.

Solution

First, the mutt utility must be installed.  There are both
OpenServer and UnixWare versions of this utility.
  For OpenServer5:
  ---------------
ftp://ftp2.sco.com/pub/skunkware/osr5/vols/mutt-1.2.5.1-VOLS.tar

The OpenServer5 version of mutt requires another skunkware package be installed, ncurses:

ftp://ftp2.sco.com/pub/skunkware/osr5/vols/ncurses-4.2-VOLS.tar

Un-tar each utility separately and use the scoadmin software manager, or custom, to install this software.

  For OpenServer6:
  ---------------
ftp://ftp2.sco.com/pub/skunkware/osr6/vols/mutt-1.4.2.1iSa-VOLS.cpio
and install as above.
Mutt is installed in /bin/mutt

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

sendmail="/usr/lib/mail/execmail"
in the Muttrc file.
  For UnixWare7:
  -------------
ftp://ftp2.sco.com/pub/skunkware/uw7/mail/mutt/mutt-1.2.5.1.pkg
This package does not need to be un-tared or uncompressed, simply
download it and run "pkgadd -d `pwd`/mutt-1.2.5.1.pkg".
  Usage:
  -----
Standard Method:
# mutt -x -a <file to attach> -s <subject> email_addr < mail.body.txt
Alternate Method:

Once when the software has been installed, the following syntax can be used to send an email, with an attachment to an email address:

# echo ""  | mutt -a /dir/file -s "Subject" user@domain.com
This will send an email, with an empty body, to
user@domain.com, with the subject of "Subject" and the
file /dir/file attached to the email.  If you wish to have
a body to this email, you can enter it within the first pair of
quotes or you can create a text file and use cat instead
of echo, as in:
# cat /dir/body.txt | mutt -a /dir/file -s "Subject" user@domain.com
NOTE:     The mutt command will also allow you to set the From: sender address
          via a muttrc file.  To do so, you could create a /dir/muttrc file
          with these contents:
set use_from
my_hdr From: "System Mail processing" <mail@domain.com>

This can then be referenced with mutt using the -F option:

# cat /dir/body.txt |\
    mutt -a /dir/file -s "Subject" -F /dir/muttrc  user@domain.com

See also

TA107230 "MMDF Troubleshooting Techniques". TA107702 "Basic troubleshooting for sendmail".

From the Xinuos technical article database, record 125337. Reproduced with permission. The original is at www.sco.com/ta/125337, 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.