You can't really do this. Mutt was not meant for sending messages programmatically, it's meant to be an interactive mail client; the command-line flags for sending messages are there only as a minor add-on, there is much that is not possible in that way.
The my_hdr
command isn't supposed to be used to set MIME headers like Content-Type
. It doesn't really work even when you don't include an attachment. The message from your second command would have two Content-Type
headers; the first one that mutt generates which states that the message is text/plain
, and the second one that you specified. It just happens that the client you're using to check the message is looking at your header. For me mutt will display that message as HTML, but thunderbird will display the un-rendered document.
When trying to combine sending HTML and an attachment, the same thing happens. There are multiple Content-Type
headers. The first is from mutt saying that the message is multipart/mixed
, the second saying that it's text/html
. In my testing mutt will again respect the second header and so try to render the entire message, including the attachment, as HTML. Thunderbird again honors the first Content-Type
header and so finds two parts, the HTML and the attachment, but the HTML part doesn't have a Content-Type
header of its own specifying that it is HTML, so it isn't rendered as such instead the raw source is shown.
You could get somewhat close by sending both the HTML and the PDF as attachments, with an empty body:
mutt -s "Subject" -a mybody.html -a file.pdf -- [email protected] < /dev/null
But you'd likely be better off using a tool that was actually designed to send more complex messages programmatically.