Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send HTML email using linux command line

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

like image 648
Oleh Herych Avatar asked Apr 07 '10 10:04

Oleh Herych


People also ask

Can I send email from Linux command line?

sendmail Command Sendmail is one of the most popular SMTP servers in Linux. You can easily send emails directly from the command line using the sendmail command. To route the information, the sendmail command makes use of the network configured on your system.


2 Answers

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] 
like image 94
Dude Avatar answered Sep 18 '22 15:09

Dude


My version of mail does not have --append and it too smart for the echo -e \n-trick (it simply replaces \n with space). It does, however, have -a:

mail -a "Content-type: text/html" -s "Built notification" [email protected] < /var/www/report.html 
like image 35
Ole Tange Avatar answered Sep 18 '22 15:09

Ole Tange