Search code examples
linuxemailmailx

How do I put the output of a file in the email body as opposed to an attachment?


I'm using Amazon Linux. I found the following for sending the contents of a file as an attachment

cat /tmp/output.txt | mailx -s "Subject" "[email protected]"

But what I want to do is send the contents of the file as the body of the email, as opposed to an attachment. How do I do this?


Solution

  • You man use "lower level" sendmail program.

    #!/bin/sh
    # cat - ... <<END - cat reads "here document" via its stdin
    # empty line after email headers IS REQUIRED
    
    cat - /tmp/output.txt <<END | /usr/sbin/sendmail -- [email protected]
    Subject: Subject
    To: [email protected]
    
    END