Sending HTML Email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sending HTML Email
# 1  
Old 08-05-2013
Sending HTML Email

1) Can you please provide me with a best example of how to send an HTML email via mutt or mail or send email commands using bash shell.

2) I tried below but i am not able to get the variable values in the HTML email output.

Code:
(cat <<-EOT
<html>
<head><title></title> </head>
<body>
<p>Hello, world!</p>
<table border="1">
<tr>
        <th>HASH_TOTALS</th>
        <th>HASH_TOTALS_COMP</th>
        <th>DIFFERENCE</th>
</tr>
</tr>
        <td>`printf "%s" "$TOT_LOAN_ROW_COUNT"`</td>
        <td>$COMP_LOAN_ROW_COUNT</td>
        <td>$COMP_LOAN_ROW_COUNT</td>
</tr>
</table>
</body>
</html>
EOT
) | mutt -e "my_hdr Content-Type: text/html" "xyz@123456.com" -s "html test"

Output:
Quote:
HASH_TOTALS HASH_TOTALS_COMP DIFFERENCE
It is just printing headers but not expanding the variables.

thank you.
# 2  
Old 08-05-2013
Try simply echoing:
Code:
{
        echo "
        <html>
        <head><title></title> </head>
        <body>
                <p>Hello, world!</p>
                <table border="1">
                <tr>
                        <th>HASH_TOTALS</th>
                        <th>HASH_TOTALS_COMP</th>
                        <th>DIFFERENCE</th>
                </tr>
                <tr>
                        <td>${TOT_LOAN_ROW_COUNT}</td>
                        <td>${COMP_LOAN_ROW_COUNT}</td>
                        <td>${COMP_LOAN_ROW_COUNT}</td>
                </tr>
                </table>
        </body>
        </html>
        "
} | mutt -e "my_hdr Content-Type: text/html" "xyz@123456.com" -s "html test"

This User Gave Thanks to Yoda For This Post:
# 3  
Old 08-05-2013
What shell are you using? in my bash, it works perfectly, expanding the variables as desired. Try it without the pipe to mutt first.
# 4  
Old 08-06-2013
Quote:
Originally Posted by Yoda
Try simply echoing:
Code:
{
        echo "
        <html>
        <head><title></title> </head>
        <body>
                <p>Hello, world!</p>
                <table border="1">
                <tr>
                        <th>HASH_TOTALS</th>
                        <th>HASH_TOTALS_COMP</th>
                        <th>DIFFERENCE</th>
                </tr>
                <tr>
                        <td>${TOT_LOAN_ROW_COUNT}</td>
                        <td>${COMP_LOAN_ROW_COUNT}</td>
                        <td>${COMP_LOAN_ROW_COUNT}</td>
                </tr>
                </table>
        </body>
        </html>
        "
} | mutt -e "my_hdr Content-Type: text/html" "xyz@123456.com" -s "html test"

how do i put thousand seperator & () for negative numbers inside the HTML table like
Code:
519,090,514.68

&
Code:
(0.32)

for -.32.

I am using bc for finding the difference from which i got negative numbers example:
Code:
`echo ${TOT_BOOK_VALUE_DOLLARS}-${COMP_BOOK_VALUE_DOLLARS} | bc`

# 5  
Old 08-06-2013
Yes, you can use bc for floating point comparison and sed to put thousand separator.

Here is an example checking the value of variable: TOT_LOAN_ROW_COUNT
Code:
if [ $( echo "$TOT_LOAN_ROW_COUNT < 0" | bc ) -eq 1 ]
then
        TOT_LOAN_ROW_COUNT="(${TOT_LOAN_ROW_COUNT})"
else
        TOT_LOAN_ROW_COUNT=$( echo "$TOT_LOAN_ROW_COUNT" | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' )
fi

# 6  
Old 08-06-2013
With some implementations of the printf utility (not all, because it is not required to support either the apostrophe flag or floating point), you can easily format the value to contain a thousands separator and then add the parenthesis for negative values with sed:
Code:
printf "%'.2f\n" "$amount" | sed 's/^\(-.*\)/(&)/'

Regards,
Alister
# 7  
Old 08-07-2013
Quote:
Originally Posted by alister
With some implementations of the printf utility (not all, because it is not required to support either the apostrophe flag or floating point), you can easily format the value to contain a thousands separator and then add the parenthesis for negative values with sed:
Code:
printf "%'.2f\n" "$amount" | sed 's/^\(-.*\)/(&)/'

Regards,
Alister
I executed the below statement i still see the hyphen symbol "-" prepended, is there a way to remove that as well.

Code:
printf "%'.2f\n" "-501.12" | sed 's/^\(-.*\)/(&)/'

Output:
Code:
(-501.12)

thanks much, appreciate it.

Last edited by Ariean; 08-07-2013 at 10:20 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HTML not coming while sending using email

echo "$1" > test.txt awk 'BEGIN{ FS="|" print "MIME-Version: 1.0" print "Content-Type: text/html" print "Content-Disposition: inline" print "<HTML>""<TABLE border="1"><TH>Heading1</TH><TH>Heading2</TH><TH>Heading3</TH>" } { printf "<TR>" for(i=1;i<=NF;i++) printf "<TD>%s</TD>", $i... (2 Replies)
Discussion started by: ATWC
2 Replies

2. Shell Programming and Scripting

Need help in sending html mail with attachment

Hi Everyone, I am facing problems in sending html mail with attachemnt. I will able to send mail with attachment (plain text ) using mailx -s and uuencode command and also html mail without attachment using sendmail option. However I am not able to send html mail along with attachment.Either... (2 Replies)
Discussion started by: karthik adiga
2 Replies

3. Shell Programming and Scripting

[Solved] Sending a HTML email from cli loses formatting.

Hi, I have a .sh file, to email a report of our backups from a linux machine. It looks like this (minus a few bits): echo "HELO $host.$domain" sleep 1 echo "mail from: vdrreport@$domain" sleep 1 echo "rcpt to:$mailto" sleep 1 echo "data" sleep 1 echo "subject: $host VDR-Report... (2 Replies)
Discussion started by: cognito
2 Replies

4. Shell Programming and Scripting

Sending a csv attachment and html text together.

Hello, I need to send below text (in a file ABC)as html text in mail body and the same as csv attachment 1,2,3 4,5,6 7,8,9 but to send as html text in mailbody we use echo "Subject: Report " | cat - ABC | /usr/lib/sendmail -t a@xyz.com and to send as an attachment in csv format we... (9 Replies)
Discussion started by: skhichi
9 Replies

5. UNIX for Dummies Questions & Answers

Sending html email with html attachment

Hello, I have a script which is sending an html file as an attachment. #!/usr/bin/ksh export MAILTO="user@company.com" export CONTENT="/usr/tmp/file.html" export SUBJECT="EmailSubject" ( echo "Subject: $SUBJECT" echo "MIME-Version: 1.0" echo "Content-Type: text/html" echo... (0 Replies)
Discussion started by: sreenathkg
0 Replies

6. Shell Programming and Scripting

Using top command to email if process is exceeding 25% and sending an email alert if so

This is my first time writing a script and Im having some trouble, Im trying to use the top command to monitor processes and the amount of CPU usage they require, my aim is to get an email if a process takes over a certain percentage of CPU usage I tried grep Obviosly that hasnt worked, Any... (8 Replies)
Discussion started by: jay02
8 Replies

7. Shell Programming and Scripting

Sending HTML Email through mailx

Hi, I am trying to send html email using mailx like follow on sh shell (Bourne) on HP-UX: mailx -s "Test HTML output in outlook MIME-Version: 1.0 Content-Type: text/html" receiver@host.com < file.txt Content of file.txt are as follows: <html> <h2>An important link to look at!</h2>... (3 Replies)
Discussion started by: manubatham20
3 Replies

8. Shell Programming and Scripting

Sending HTML attachment through mail

Hi I am new to unix and scripting.I am trying to send a html file as an attachment. SUBJECT="Type of Exceptions in Application" TO=Sushovan.Samals@gmail.com SPOOLFILE=/data/reg/tlogs/Monitor.html #echo "Send the E-mail message..." uuencode $SPOOLFILE $SPOOLFILE | mailx -s "$SUBJECT" $TO... (2 Replies)
Discussion started by: sushovan
2 Replies

9. UNIX for Dummies Questions & Answers

sending mail with html content

hi, I am new to unix. I need send html content as a mail from my sun-solaris2.6 work station. When I tried that the recipient gets it as html code with all the tags. any solutions? thanx in advance (2 Replies)
Discussion started by: gmchoudary
2 Replies

10. Shell Programming and Scripting

Sending mail from Unix - For html output

I have automated some checks - and I want to send a email when there is an issue. This is fine and I can send the email. However - I want to generate the email in html format so I can highlight any issues to a reader.. ie. If there is a disk space issue - then the email will highlight the... (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question