I am working with a locked-down RHEL box.

The goal is to send an email with a file attached.

The only mail service available is sendmail (cannnot use sendemail, mail, mailx, mutt, etc.)

In addition, the uuencode command cannot be found and I cannot install sharutils.

I have verified that sendmail works with the simple test below:

echo "Subject: testing" | sendmail -v myemail@address.com

I have tried the command below but it just creates a dead.letter:

echo "Subject: testing" | sendmail /a /tmp/test.txt myemail@address.com

What is the correct way to send a file from the server using sendmail given the constaints?

  • does the system has mpack? sending email in this form might not be advisable for binary content. Dec 7 '17 at 16:59
  • 2
    sendmail is not the program to use to create the email, you need something else like mail or mutt to format the email correctly (including encoding the attachment in it) before feeding it to sendmail for delivery. They serve difference purposes: sendmail is an MTA to Transmit emails where mail/mutt are MUAs, that is Mail User Agent to build or view emails. Dec 7 '17 at 16:59
  • @PatrickMevzek interesting.. I did not recognize the distinction Dec 7 '17 at 17:08
  • @RuiFRibeiro mpack does not appear to be installled Dec 7 '17 at 17:08

The work-around was to use openssl base64 encoding like so:

( echo "to: myaddress@email.com"
  echo "subject: Message from the server"
  echo "mime-version: 1.0"
  echo "content-type: multipart/related; boundary=messageBoundary"
  echo "--messageBoundary"
  echo "content-type: text/plain"
  echo "Please find the document attached."
  echo "--messageBoundary"
  echo "content-type: text; name=test.txt"
  echo "content-transfer-encoding: base64"
  openssl base64 < /tmp/test.txt) | sendmail -t -i

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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