Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If you use e.g. Solaris without additional installed software to send MIME mails: how can you send mails with MIME attachments with standard command line tools?

share|improve this question

You can use the following fragment in a shell script. This is admittedly a very ugly hack, so do use this only for uncritical things. I think it is possible that it adds a byte or two at the end of the file, but otherwise it seems to work fine.

mail ${mailinglist} << END_MAIL
To: ${mailinglist}
From: ${mailsender}
Subject: ${subject}
Content-Type: multipart/mixed; boundary="_NextPart_"
Content-Type: text/plain; charset=us-ascii

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.



here is

Content-Type: application/x-zip-compressed;
Content-Transfer-Encoding: base64
Content-Disposition: attachment;

uuencode | sed -e 's/^end$/~~~/' | tail +2 | cut -c 2- | 
tr ' !"#$%&\047()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\133\134\135^_' \
 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' | 
sed -e 's/^~~$/==/' 


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.