I want to send an HTML report that is piped from another command, eg: mycommandthatprintshtml | mail [email protected] . 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?
Asked
Active
Viewed 7,891 times
2 Answers
5
In addition to the email body, you also need to print the email headers:
echo "From: [email protected]\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 protected]
Note that From, Date, Subject are mandatory. MIME-Version and Content-Type are there to help the recipient understand how the email is formatted.
Frederik Deweerdt
- 3,722
- 17
- 18
-
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 https://unix.stackexchange.com/a/250189/182991 – bvj Sep 30 '18 at 05:57
-
@Giel SSMTP adds message id when necessary on my servers. I know I'm a bit late, but maybe someone else will neeed that information. – Kamil Jan 16 '23 at 16:55
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: [email protected]
bcc: [email protected]
From: [email protected]
MIME-Version: 1.0
Content-Type: text; charset=utf-8
Subject: Some subject
Dear Person,
....
Zian
- 131
- 4