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]
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]
Example using uuencode:
uuencode surfing.jpeg surfing.jpeg | mail [email protected]
and reference article:
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
mailx might help as well. From the mailx man page:
-a file
Attach the given file to the message.
Pretty easy, right?
$ echo | mutt -a syslogs.tar.gz [email protected]
But it uses mutt, not mail (or mailx).