40

I have been using mutt to send emails from inside another application & it works fine. I have to send html files and currently I have to send them as attachments. So I use

mutt -s "hi" -a attach.html user@domain.com < /dev/null

But if I try to send the html file as the body as follows

mutt -e content_type=text/html Email address -s "subject" < test.html

then instead of the html file i get the source text of the html file.

Is there any way that I can make the body of the message as html instead of plain text???

svick
  • 236,525
  • 50
  • 385
  • 514
eldorado0o
  • 528
  • 1
  • 4
  • 10

5 Answers5

63

When I try your command, mutt is telling me that content_type=text/html is an unknown command. So you have to use the "set" command to make this work:

mutt -e "set content_type=text/html" Email address -s "subject" < test.html

That worked in my tests.

Bond
  • 16,071
  • 6
  • 30
  • 53
vstm
  • 12,407
  • 1
  • 51
  • 47
  • it return : error in command line "content_type" : unknown command and i get the source code insted of html body ?? – eldorado0o Jul 24 '11 at 08:56
  • 1
    @eldorado what version of mutt are you using? apparently the "content_type"-variable is not available in the version `1.4.x` or before. – vstm Jul 24 '11 at 09:04
  • Well, 1.5.21 is the most recent one (and the one i've used for testing the command). But according to the [mutt webpage](http://www.mutt.org/) it's still a development-version. If you can live with it that's okay, otherwise there are other ways to send HTML-mails. – vstm Jul 24 '11 at 09:20
  • could you please Give me The other Way TO send Html-mails ? – eldorado0o Jul 24 '11 at 15:08
  • @eldorado see [sending HTML mail using a shell script](http://stackoverflow.com/questions/3317174/sending-html-mail-using-a-shell-script). But I have read today that sending HTML-Mails only (that means without multi-part with a text/plain alternative) is increasing the possibility of getting the mail considered as SPAM (I don't have the link so "citation needed"). – vstm Jul 25 '11 at 17:46
8

I tried with mutt 1.6d and that option -e "set content_type=text/html" doesn't work for me. After search around i found below command line works for me:

mutt -e "my_hdr Content-Type: text/html" test@yahoo.com  -s "subject" < mytest.html

Reference here

LinuxQuestions

Kevin Zhu
  • 2,746
  • 26
  • 23
  • 1
    This one, on mutt 1.4 will send two headers content-type, one for plain text, other for html. what the client will show up is up to then... gmail will show the plain text, so be careful – higuita Nov 20 '14 at 15:29
  • Just for the record, this also works for version 1.5.20. – gacanepa Aug 24 '16 at 15:00
6

my mutt version is 1.4.x, and I also cannot set content_type=text/html, it is reported as unknown variable.

and I checked the mutt doc, the content_type is only supported by version 1.5.x, such as the latest version 1.5.21.

obviously, html mail was not supported by version 1.4.x.

YYGCui
  • 61
  • 1
  • 2
5

I use Mutt 1.5.23 to send an html email with embedded image, and this works for me. mutt -e "set content_type=text/html" Email -s "subject" -a pic.png < test.html

file test.html:

<html>

<head></head>

<body>
  <img src="cid:pic.png"/>
</body>
</html>
Muxiang Yang
  • 71
  • 1
  • 3
0

If you look at the source of an HTML email, you'll see at minimum something like:

Subject: test html mail
From: sender@example.com
To: recipient@example.com
Content-Type: multipart/alternative; boundary=bcaec520ea5d6918e204a8cea3b4

--bcaec520ea5d6918e204a8cea3b4
Content-Type: text/plain; charset=ISO-8859-1

*hi!*

--bcaec520ea5d6918e204a8cea3b4
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<p><b>hi!</b></p>

--bcaec520ea5d6918e204a8cea3b4--

So, you have to create a "Content-Type:" header, and add the boundaries above the text-only version, and above and below the HTML version.

Given the amount of hand-crafting required, you might as well hand the message over to sendmail instead of mutt.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • Mutt does not allow you to insert a Content-Type header. The only way is through the command line. – e18r May 07 '17 at 16:14