I want to send an HTML report that is piped from another command, eg:
mycommandthatprintshtml | mail firstname.lastname@example.org . 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: email@example.com\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 firstname.lastname@example.org
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: email@example.com bcc: firstname.lastname@example.org From: email@example.com MIME-Version: 1.0 Content-Type: text; charset=utf-8 Subject: Some subject Dear Person, ....