Find the answer to your Linux question:
Results 1 to 3 of 3
I have a RedHat server that doesn't have mutt or uuencode installed on it. I cannot install either of these utilities for procedural reasons. How do I send an email ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2014
    Posts
    1

    Send email attachment without uuencode nor mutt


    I have a RedHat server that doesn't have mutt or uuencode installed on it. I cannot install either of these utilities for procedural reasons. How do I send an email attachment via a bash script? I don't want to install any other application. The mail command works for sending emails. I just don't know how to attach a file to the emails.

  2. #2
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    882
    You can't.

  3. #3
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,048
    While there isn't the ability to add an attachment using mail, at least that I know of, it is possible to do it the grinder way.

    Untested:
    Code:
    #!/bin/bash
    
    to="$1"
    subject="$2"
    reply_to="$3"
    body="$4"
    filename="$5"
    boundary="====msg_boundary====$(date +%Y%m%d%H%M%S)====="
    data=$(base64 $filename)
    
    mail_msg="From: $reply_to\r\n";
    mail_msg+="To: $to\r\n";
    mail_msg+="Reply-To: $reply_to\r\n";
    mail_msg+="Subject: $subject\r\n";
    mail_msg+="Content-Type: multipart/mixed; boundary=\""$boundary"\"\r\n";
    mail_msg+="\r\n";
    mail_msg+="This is a MIME formatted message.\r\n";
    mail_msg+="\r\n";
    mail_msg+="--$boundary\r\n";
    mail_msg+="Content-Transfer-Encoding: 7bit\r\n";
    mail_msg+="Content-Disposition: inline\r\n";
    mail_msg+="\r\n";
    mail_msg+="$body\r\n";
    mail_msg+="\r\n";
    mail_msg+="\r\n";
    mail_msg+="--$boundary\r\n";
    mail_msg+="Content-Type: $MIMETYPE; name=\"$filename\"\r\n";
    mail_msg+="Content-Transfer-Encoding: base64\r\n";
    mail_msg+="Content-Disposition: attachment; filename=\"$filename\";\r\n";
    mail_msg+="\r\n";
    mail_msg+="$data\r\n";
    mail_msg+="\r\n";
    mail_msg+="\r\n";
    mail_msg+="--$boundary--\r\n";
    mail_msg+="\r\n";
    mail_msg+="\r\n";
    
    echo -e $mail_msg | sendmail -oi -t

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •