How to send email from ssmtp with HTML
6,977
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.
Related videos on Youtube
Author by
Zombies
Updated on September 18, 2022Comments
-
Zombies over 1 year
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? -
Giel almost 10 yearsMessage-ID is mandatory as well, or does SSMTP add it if necessary?
-
Frederik Deweerdt almost 10 yearsThe 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.
-
Benny over 7 yearsAny chance of an example with HTML message plus attachment(s)?
-
bvj over 5 years@RTF late comment, but likely possible using
multipart/mixed
. See unix.stackexchange.com/a/250189/182991