I want to send an HTML report that is piped from another command, eg:
mycommandthatprintshtml | mail email@example.com . When I do this currently, it prints all the html tags. Is there a way I can set the required headers to make it display in HTML formatted?
In addition to the email body, you also need to print the email headers:
echo "From: firstname.lastname@example.org\r\nDate: $(date)\r\nSubject: subject\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=utf-8\r\n\r\n$(mycommandthatprintshtml)" mail email@example.com
Note that From, Date, Subject are mandatory. MIME-Version and Content-Type are there to help the recipient understand how the email is formatted.
with ssmtp you can send a mail from a file and specify headers inside (similar to what Federik did)
ssmtp -t < mail.txt
to: firstname.lastname@example.org bcc: email@example.com From: firstname.lastname@example.org MIME-Version: 1.0 Content-Type: text; charset=utf-8 Subject: Some subject Dear Person, ....