I had successfully used the following on Arch Linux (where the -a
flag is used for attachments) for several years:
mailx -s "The Subject $( echo -e "\nContent-Type: text/html" [email protected] < email.html
This appended the Content-Type header to the subject header, which worked great until a recent update. Now the new line is filtered out of the -s
subject. Presumably, this was done to improve security.
Instead of relying on hacking the subject line, I now use a bash subshell:
(
echo -e "Content-Type: text/html\n"
cat mail.html
) | mail -s "The Subject" -t [email protected]
And since we are really only using mailx
's subject flag, it seems there is no reason not to switch to sendmail
as suggested by @dogbane:
(
echo "To: [email protected]"
echo "Subject: The Subject"
echo "Content-Type: text/html"
echo
cat mail.html
) | sendmail -t
The use of bash subshells avoids having to create a temporary file.