views:

1744

answers:

4

I'm on a server running a Linux shell. I need to mail a simple file to a recipient. How to do this, prefereably using only the mail command?

UPDATE: got a good solution, using mutt instead:

$ echo | mutt -a syslogs.tar.gz [email protected]
+3  A: 

Example using uuencode:

uuencode surfing.jpeg surfing.jpeg | mail [email protected]

and reference article:

http://www.shelldorado.com/articles/mailattachments.html

Jon
Commentary on http://archives.neohapsis.com/archives/postfix/2008-10/0422.html ?
chaos
Is uuencode a "default" GNU tool? My box doesn't seem to have it.
Seiti
The reference article was really useful! Thanks!
Seiti
A: 

My answer needs base64 in addition to mail, but some uuencode versions can also do base64 with -m, or you can forget about mime and use the plain uuencode output...

   [email protected]
   [email protected]
   SUBJECT="Auto emailed"
   MIME="application/x-gzip"  # Adjust this to the proper mime-type of file
   FILE=somefile.tar.gz
   ENCODING=base64  
   boundary="---my-unlikely-text-for-mime-boundary---$$--" 

   (cat <<EOF
    From: $FROM
    To: $REPORT_DEST
    Subject: $SUBJECT
    Date: $(date +"%a, %e %Y %T %z")
    Mime-Version: 1.0
    Content-Type: multipart/mixed; boundary="$boundary"
    Content-Disposition: inline

    --$boundary
    Content-Type: text/plain; charset=us-ascii
    Content-Disposition: inline

    This email has attached the file

    --$boundary
    Content-Type: $MIME;name="$attachment"
    Content-Disposition: attachment;filename="$attachment"
    Content-Transfer-Encoding: $ENCODING

    EOF
    base64 $attachment
    echo ""
    echo "--$boundary--" ) | mail
njsf
+2  A: 

mailx might help as well. From the mailx man page:

-a file
     Attach the given file to the message.

Pretty easy, right?

David Winslow
A: 
$ echo | mutt -a syslogs.tar.gz [email protected]

But it uses mutt, not mail (or mailx).

Seiti