*attaching* a file to /usr/bin/mail message

Ean Kingston ean at hedron.org
Mon Apr 4 09:21:07 PDT 2005


> On 2005-04-02 14:08, "Colin J. Raven" <colin at kenmore.kozy-kabin.nl> wrote:
>> Does anyone happen to know how you would *attach* *not readin the
>> contents of, but actually *attach*) a file using /usr/bin/mail?
>
> Not very easily, is one answer.  You can probably get away with uuencode
> output filtered to the standard input of mail(1), but that's not really
> a "MIME attachment".

Okay, if you really want to use mail, here is what a mail message
(suitable for sending through /usr/bin/mail looks like when it has a
UUEncoded attachement. Technically you are supposed to MIME-Encode the
attachment but pretty much every mail client that supports attachments
will read a UUEncoded attachment.

From: "System Administrator"<root at example.com>
To: "test user"<test at example.com>
Subject: Testing mail attachments.
Content-Type: multipart/mixed;
        boundary="This_can_not_match_any_other_line_in_the_message"
MIME-Verion: 1.0

--This_can_not_match_any_other_line_in_the_message
Content-Transfer-Encoding: quoted-printable
Content-type: text/plain

Hi, Attached is a simple text file to test multi-part sending. The file was
originally called sample.txt and was created on a SUN system.

Notice the string specified in the boundary="..." bit in the headers. That
string should not occur anywhere in the body except as part of the mime
part delimitters.

--This_can_not_match_any_other_line_in_the_message
Content-Transfer-Encoding: x-uuencode
Content-Type: text/plain;
        name="sample.txt"
Content-Disposition: attachment;
        filename="sample.txt"

begin 644 sample.txt
M5&AI<R!I<R!A('-A;7!L92!F:6QE('1H870@=VEL;"!B92!U=65N8V]D960@
M=&\@8F4 at 9&5L:79E<F5D(&%S(&%N(&4M;6%I; IA='1A8VAM96YT+B!)="!I
M<RP@;V)V:6]U<VQY(&$@=&5X="!F:6QE+ at H*5&AI<R!S:&]U;&0 at 8F4@=&AE
.(&9O=7)T:"!L:6YE+ at H@

end

--This_can_not_match_any_other_line_in_the_message--

You use it like this:

/usr/bin/mail test at example.com < mail_with_attachment.txt

Obviously, you will have to uuencode your own attachment and replace the
one from the example.

>
>> On my system mail has no "-a" (attach) flag, and some Googling told me
>> mailx might solve the problem, but /usr/bin/mailx just invokes mail....
>
> Other mail user agents do have a -a flag though.  At least mail/mutt
> does and I've used it successfully in the past.  If you are not stuck
> with mail(1) only, you can always use mutt for this.
>
> 	mutt -a /path/to/file recipient.address at example.net
>
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe at freebsd.org"
>


-- 
Ean Kingston
    E-Mail: ean_AT_hedron_DOT_org
 PGP KeyID: 1024D/CBC5D6BB
       URL: http://www.hedron.org/




More information about the freebsd-questions mailing list