I want to send a html message with Mailx. When I try the following command
mailx -s "Subject" [email protected] < email.html
I get the content of email.html in plain text. In the message the header Content-Type is set to text/plain. The -a option tries to send a file so I didn't find out how to modify the header. This answer almost worked, it sets well the Content-Type to text/html but doesn't substitute the default Content-Type which is text/plain.
mailx -s "$(echo -e "This is the subject\nContent-Type: text/html")" [email protected] < email.html
gives this result :
From: [email protected]
To: [email protected]
Subject: This is the subject
Content-Type: text/html
Message-ID: <538d7b66.Xs0x9HsxnJKUFWuI%[email protected]>
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
boundary="=_538d7b66.z5gaIQnlwb1f/AOkuuC+GwF1evCaG/XIHQMbMMxbY6satTjK"
This is a multi-part message in MIME format.
--=_538d7b66.z5gaIQnlwb1f/AOkuuC+GwF1evCaG/XIHQMbMMxbY6satTjK
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
<html>
<body>
<p>Helo wolrd</p>
</body>
</html>
PS : I also tried with uuencode. When I try to display the message in the webmail I get a blank page...
It's easy, if your mailx
command supports the -a
(append header) option:
$ mailx -a 'Content-Type: text/html' -s "my subject" [email protected] < email.html
If it doesn't, try using sendmail
:
# create a header file
$ cat mailheader
To: [email protected]
Subject: my subject
Content-Type: text/html
# send
$ cat mailheader email.html | sendmail -t