0

I am trying to attach one file and send few echo messages in the Body of an email using mailx and uuencode. I have below command which I have added them together, and uuencode doesn't work properly but I get echo message properly in my email.

How can I make uuencode works here? Something wrong I am doing here I guess while combing uuencode with mailx?

(uuencode /tmp/chart.html percentage_graph.html) | mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r rj@host.com rj@host.com <<EOF
Data Successfully loaded into LIP_DATA_QUALITY table

Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`

Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`

Error Percentage: $QUERY2
EOF

But for testing purpose if I issue below command to see whether I am getting any html file or not in an attachment, then I get an email with the attachment properly.

(uuencode /tmp/chart.html percentage_graph.html) | mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r rj@host.com rj@host.com

Then what's wrong in my first command when I combine them together?

arsenal
  • 23,366
  • 85
  • 225
  • 331
  • Probably has something to do with the pipeline and the heredoc both trying to send data to mailx's stdin. – jordanm Aug 13 '12 at 23:14
  • So how can I add `uuencode command` such that I get both the things together? – arsenal Aug 13 '12 at 23:16
  • What's this about you and @Nevzz03 asking near-identical questions all the time? See (tangentially related, not duplicate) http://stackoverflow.com/questions/11944124/send-the-output-of-html-file-within-the-email-body – tripleee Aug 14 '12 at 04:31

2 Answers2

1

The mailx command can get its input from the pipe (uuencode) or the heredoc (<< EOF). But not both.

This may work for you:

$ mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r rj@example.com rj@example.com <<EOF
Data Successfully loaded into LIP_DATA_QUALITY table

Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`

Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`

Error Percentage: $QUERY2

$(uuencode /tmp/chart.html percentage_graph.html)

EOF

Alternately, consider using something like mutt which will let you attach files separately from the body of the message.

ghoti
  • 45,319
  • 8
  • 65
  • 104
  • 1
    the heredoc feeds to the stdin of the entire pipeline (so to the stdin of uuencode, not mailx) – Chris Dodd Aug 13 '12 at 23:54
  • @ChrisDodd - yes, but that's not how the OP was using it. `uuencode` only takes stdin if you run it with a single option, the remote filename. The OP is taking `/tmp/chart.html`, naming it `percentage_graph.html` and trying to embed that in the body of the message a la email circa early 1990s, before MIME was invented. His intent was to "**attach one file**". – ghoti Aug 14 '12 at 03:06
0

uuencode doesn't read stdin if you give it an input filename as you have done here. That's because it encodes a single file. if you want to encode two files, you need to combine them together somehow first. You could just use cat if concantenating them is ok:

cat /tmp/chart.html - | uuencode percentage_graph.html | mailx .... << EOF
..stuff to append to chart.html
EOF
Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • This uuencodes the text into the same block as the HTML file, so the resultant "attachment" will be corrupt HTML rather than text with a uuencoded HTML file embedded. The recipient would need to uudecode the data in order to read the text of the message, which I think is not what the OP was aiming at. – ghoti Aug 14 '12 at 03:11