Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, This is not a perl question but I have found this forum really helpful so I just bring it up in here: Does anyone know how to add a text file as an attachment using unix mail command ( can be mailto or any other unix mail command)? Thank you for all the helps ginger

Replies are listed 'Best First'.
Re: attach with unix mail
by spartacus9 (Beadle) on Sep 26, 2002 at 02:32 UTC
    okay, i know you said the question was unix in nature and not perl, but since this is perl site, i am going to offer you a perl answer.

    you can use the Mail::Sender module to easily send attachments. Below is an example of such:
    ref ($sender = new Mail::Sender({ from => 'you@abc.com', smtp => 'smtp.server.com'} )) or die "$Mail::Sender::Error\n"; (ref ($sender->MailFile({ to =>'recipient@xyc.com', subject => "Here is the file", msg => "Attached is your file", file => "$filename" }))
Re: attach with unix mail
by insensate (Hermit) on Sep 25, 2002 at 23:53 UTC
    As far as I know, mailx can't do this. To swing this post back On-Topic I will recommend the module Mime::Lite. You could use this to write your own mail tool that accepts to/subject/body/attachment as parameters.
    Jason
Re: attach with unix mail
by greenFox (Vicar) on Sep 26, 2002 at 00:02 UTC

    Waaay off-topic but any-way a google search for "attach file unix" has Sending email with attachments on UNIX systems as the first match which links this perl script using MIME::Lite.

    google is your friend!

    Are we back on-topic now? :)

    Update: fix broken URL's

    --
    Until you've lost your reputation, you never realize what a burden it was or what freedom really is. -Margaret Mitchell

Re: attach with unix mail
by zentara (Cardinal) on Sep 26, 2002 at 16:06 UTC
    It isn't "unix mail" but:
    mutt -s "subject" -a somefile.tar.bz2 foo@foo.com < mailbody
Re: attach with unix mail
by Anonymous Monk on Sep 26, 2002 at 17:30 UTC
    Thank you for everything. Finally I made it with mutt. With the echo, it always gives me 'receipants must be specified'. It is a command in my shell script file so I'd rather resort to a unix cmd. I really appreciate help of you all. Wish you all the best. ginger
Re: attach with unix mail
by Anonymous Monk on Sep 27, 2002 at 17:04 UTC
    hello, It is me again. I tried to attach a 18MB text file with mutt but it has been 3.5 hrs and I have not got it yet. It works with 65kB file. It is under linux. Could someone tell me what the problem might be? Thank you ginger

      I never tried it, but I think you can use sendfiles, a shell script from nmh - Message Handling System. Its man page says:

      The shell script sendfiles, is used to send a collection of files an +d directories via electronic mail. sendfiles mailpath "subject" files ... sendfiles will archive the files and directories you name with the tar + (1) command, and then mail the compressed archive to the `mailpath' with the give +n `subject'. The archive will be automatically split up into as many messages as necess +ary in order to get past most mailers.

      This should solve your problem. Ciao, Valerio