Mailx send html message

email, html, linux, mailx

Solution

It's easy, if your `mailx` command supports the `-a` (append header) option:

$ mailx -a 'Content-Type: text/html' -s "my subject" user@gmail.com < email.html

If it doesn't, try using `sendmail`:

# create a header file
$ cat mailheader
To: user@gmail.com
Subject: my subject
Content-Type: text/html

# send
$ cat mailheader email.html | sendmail -t

Problem

I want to send a html message with Mailx. When I try the following command ``` mailx -s "Subject" user@gmail.com < 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")" user@gmail.com < email.html ``` gives this result : ``` From: send@gmail.com To: user@gmail.com Subject: This is the subject Content-Type: text/html Message-ID: <538d7b66.Xs0x9HsxnJKUFWuI%maikeul06@gmail.com> 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...

Original source

Related problems