Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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.

--_NextPart_

Hallo,

here is whatever.zip.

--_NextPart_
Content-Type: application/x-zip-compressed;
 name="whatever.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="whatever.zip"

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

--_NextPart_--

END_MAIL
share|improve this answer

Your Answer

 
discard

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.