Designing a MIME-Capable Replacement for /bin/mail
Many people send email from CGI scripts or from cron jobs. Wouldn’t life be better if that mail were MIME compliant? For example, a cron job that checks for errors in a log might attach the log for review by a remote administrator. Here we will show how a Perl script can be created that fills this role, as a replacement for /bin/mail, the most likely candidate for replacement. Unlike /bin/mail, though, it would be good if our cross-platform Perl interpreter could run a cross-platform script. That can be accomplished by speaking SMTP directly to a mail server, instead of relying on locally installed mail software that could be system dependent.
The Unix /bin/mail program can be used to send simple text mail messages. The command-line syntax accepted by /bin/mail when used for sending mail is:
mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr...
The options are described in the man page as follows:
- -i
Ignore tty interrupt signals. This is particularly useful when using mail on noisy phone lines.
- -I
Forces mail to run in interactive mode even when input isn’t a terminal. In particular, the “~” special character when sending mail is only active in interactive mode.
- -n
Inhibits reading /etc/mail.rc upon startup.
- -v
Verbose mode. The details of delivery are displayed on the user’s terminal.
- -s
Specify subject on command line (only the first argument after the -s flag is used as a subject; be careful to quote subjects containing spaces). ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access