Sending Files; Using mhmail and viamail

[previous] [next] [table of contents] [index]

Most users use comp to send mail interactively. MH also comes with a command called mhmail. Instead of having a components file, mhmail has switches called -subject, -cc, and so on. If you have a text file that you want to send in a mail message, there are a few ways to do it. (The file should have just text -- usually, that's letters, digits, and punctuation -- unless you're using a multimedia mail standard like MIME. You shouldn't mail nontext files without special processing such as uuencode(1). Your other choice is to use viamail, the MIME file-sending script explained later in this section.)

The Section Mailing Non-interactively: mhmail has more mhmail techniques.

If both you and the recipient have MIME-capable MH systems, you can use the viamail script. viamail is explained at the end of the mhn(1) manual page. It packages one or more files with the tar(1) and compress(1) commands. It sends the files as an application/octet-stream content with base64 encoding. The encoded message will have the Content-type: parameters type=tar and x-conversions=compress, as well as the comment (extract with uncompress | tar xvpf -). If needed, viamail will split the data into several message/partial messages.

You probably shouldn't use viamail unless you're sure that the recipient can handle the message. Unfortunately, a lot of MIME user agents can't handle partial messages. The recipient can reassemble the parts by hand, but it's tedious; a program like one of the newer versions of shar will make life a lot easier for the recipient. But viamail does use the robust, reliable MIME standard -- so it may be worth the work for the recipient.

For some reason, viamail is in the MH library directory. So, to use it, unless the library directory is in your shell's search path, you need to type the absolute pathname of the library directory. The first viamail argument (except for the option -- see below) is the address you want to send the files to. You can use more than one address, separated by commas and inside quotes (see below). Next comes the subject, which is required; you should quote it. Finally, give the filename(s) you want to send.

Here's an example of sending the files ch01 and ch02 to fred and ehuser@xyz.edu. The message subject is Chapters 1 and 2:

% /usr/local/mh/lib/viamail "fred,ehuser@xyz.edu" "Chapters 1 and 2" ch01 ch02
mailpath = fred,ehuser@xyz.edu
subject-string = Chapters 1 and 2
files = ch01 ch02
a ch01 44 blocks
a ch02 37 blocks
After it repeats the addresses, subject and filenames, viamail runs tar(1) with its v (verbose) flag; you'll see the output as tar archives the files.

The message will be sent From: you unless the undocumented PERSON environment variable has been set to a different address. The message parts are sent right away unless you add an option (which has to be first, before the addresses!) that tells viamail how many seconds to pause between the parts. For instance, to send the mail from elsa@relesi.za and pause one minute (60 seconds) between the parts:

% setenv PERSON 'elsa@relesi.za'
% /usr/local/mh/lib/viamail -60 "fred,ehuser@xyz.edu" "Chapters 1 and 2" ch01 ch02
The PERSON address can't be a complete RFC 822 address such as "G. Vidal" <gore@xyz.edu>. It has to be a plain address in the format username or username@host.domain.

Add Files to Your Drafts: append

To add the contents of a file to your draft message, you can always go into an editor such as vi and use its read file (:r) command. But that's not very efficient, especially for attaching several files.

The paper "MH.5: How to Process 200 Messages a Day and Still Get Some Real Work Done," by Marshall T. Rose and John L. Romine, has a shell script called append. (There's also a version, with work by Bob Desinger, in the miscellany/scripts directory of the MH distribution. It comes with an online manual page.)

This book's online archive has a version of append that lets you type more than one filename; it also allows wildcards, environment variables, and abbreviated filenames. You call it as an editor at the What now? prompt. For example, to append a copy of your file, report to your draft message:

What now? edit append report
After it appends the file(s), you get another What now? prompt. If you want to separate the files you append with blank lines, rows of dashes, or whatever, an easy way to do so is to make a little file named something like separator with that separator in it:
% cat separator
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This next example shows how to append all the files from the $HOME/proj directory whose names end with .out, then your separator file, and then a file in the current directory named .signature:
What now? e append $HOME/proj/*.out sep .signature
The sep above is an abbreviation for the separator file's full filename. See the explanation of append.

The Section Add Text to Drafts: mysend shows a way to add files automatically: a sendproc script. The Section Automatic Signature on End of Messages has a simpler way to add text (like a signature) every time you send a message: by changing your draft message template files. mhn can add files, too, in MIME format, with the # directive -- see the Section Composing and Sending MIME Messages.

[Table of Contents] [Index] [Previous: Distributing Messages with dist] [Next: Chapter Introduction: Finding and Organizing Mail with MH]


Last change $Date: 1996/06/06 15:14:08 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jerry@ora.com>

Questions or problems regarding this web site should be directed to Steve Gielda.
Copyright 1999 www.cotse.com.  All rights reserved.
Last modified: Friday April 02, 1999.