0

I am try to send a mail with HTML table by reading data from a text file. The table is getting formatted properly and can be seen in mail body but i also want the same text file to be send in same mail as an attachment.

Here is the code I am using:

awk -F '|' '
        BEGIN {
                print "From: abcdef@xyz.com"
                print "To: abcdef@xyz.com"
                print "MIME-Version: 1.0"
                print "Content-Type: text/html"
                print "Subject: Utilization Report"
                print "<html><body><font face=verdana size=2 color=black ></br></br> Body of mail. </br>  </br></br> <B> Notes of mail.</b></br></br> " 
                print "<table border=1 cellspacing=1 cellpadding=1 height="75">"



        }
        !/^#/ && /^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                        print "<td> <center> <font face=verdana size=2> " $i " </center></td>"
                print "</tr>"
        }
        !/^#/ && !/^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                        print "<td> <center> <font face=verdana size=2> " $i " </center></td>"
                print "</tr>"
        }
        END {
                print "</table></body></html>"
        }
' /path-of-file/filename.txt | /usr/sbin/sendmail -t  uuencode /path-of-file/filename.txt
  • You will need to construct a "multipart" message. Examples can be found. Been there, done that, but never with awk. – Gerard H. Pille Jan 28 at 22:32
  • This feels like it would be difficult to do in awk. If awk is a requirement, it should be a tag. You can click the edit button under your post to add that tag. If it's not a requirement, what else would you be open to? bash, zsh, python, perl, and ruby are all options that feel to me like they'd be easier than awk. Of course, I'm not an awk enthusiast; it could be someone who uses awk all the time would know better how to do that - which is one of the two reasons you should have the awk tag if you need it to be awk. – Ed Grimm Jan 28 at 23:37
  • Thanks you Ed, I will look for some work around. Menawhile, I have added the tag ' awk'. – dumpi16 Jan 29 at 14:19

Your Answer

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

Browse other questions tagged or ask your own question.