6

I want to send an HTML report that is piped from another command, eg: mycommandthatprintshtml | mail someone@hostname.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?

5

In addition to the email body, you also need to print the email headers:

echo "From: from@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 someone@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.

  • Message-ID is mandatory as well, or does SSMTP add it if necessary? – Giel Aug 30 '14 at 12:41
  • The RFC 5322 says that the message-id should be present, but it's not mandatory. Most of the servers will add one for you if it isn't. I don't know if SSMTP adds one for you. – Frederik Deweerdt Aug 30 '14 at 16:00
  • Any chance of an example with HTML message plus attachment(s)? – RTF Oct 17 '16 at 16:12
  • @RTF late comment, but likely possible using multipart/mixed. See unix.stackexchange.com/a/250189/182991 – bvj Sep 30 '18 at 5:57
0

with ssmtp you can send a mail from a file and specify headers inside (similar to what Federik did)

ssmtp -t < mail.txt

mail.txt:

to: write.to@mail.com
bcc: hidden@mail.com
From: my.name@mail.com
MIME-Version: 1.0
Content-Type: text; charset=utf-8
Subject: Some subject

Dear Person,
....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.