How to send HTML email using linux command line

Oleh Herych picture Oleh Herych · Apr 7, 2010 · Viewed 194.7k times · Source

I need to send email with html format. I have only linux command line and command "mail".

Currently have used:

echo "To: [email protected]" > /var/www/report.csv
echo "Subject: Subject" >> /var/www/report.csv
echo "Content-Type: text/html; charset=\"us-ascii\"" >> /var/www/report.csv

echo "<html>" >> /var/www/report.csv
mysql -u ***** -p***** -H -e "select * from users LIMIT 20" dev >> /var/www/report.csv
echo "</html>" >> /var/www/report.csv

mail -s "Built notification" [email protected] < /var/www/report.csv

But in my mail-agent i get only plain/text.

alt text

Answer

Dude picture Dude · Apr 28, 2011

This worked for me:

echo "<b>HTML Message goes here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" [email protected]