I'm trying to send email with an html file as the body (it's actually a cucumber results report if that matters) or an attachment (if sending it as the body does not work) via the command line

I've tried the following based on the mutt example in this answer to another question, but it is resulting in an error.

cat <<'EOF' Audit_Results.html | mutt -H -
To: cvanderlinden@xxxxxx.com
Subject: "test sending html mail"
Content-Type: text/html


when I do this I get the following error

No recipients were specified.

Mutt was installed using brew install mutt and it looks like that installed version 1.5.21. I am able to send mail via the 'interactive' interface but just tested that with simple text mail, nothing html or with an attachment.

My objective is to send the cucumber results file "Audit_Results.html" file out as an email. Although the file includes some screenshots that are created using webdriver's .screenshot_as(:base64) method, and embedded using cucumber's embed("data:image/png;base64,#{encoded_img}",'image/png') function which seems to pose a bit of a problem. So far the one time I've managed to create a html mail from the report (using sendmail) it did not display properly in gmail. (although if sent as an attachment, it will format properly when downloaded and opened with a browser) Seems like gmail at least does not like html email with images embedded in that format. So it may be that I will end up needing to send the html report as an attachment.


If you just want to send Audit_Results.html verbatim, use this syntax:

mutt -e "set content_type=text/html" -s "Your audit results" cvanderlinden@example.com < Audit_Results.html

You won't need to pre-edit Audit_Results.html with mail headers, you can just send it directly.

| improve this answer | |
  • OK that sent things, but when viewing the mail in gmail I see the same thing I did when I accomplished this with sendmail. When it comes to the screenshot, instead of a link I can click to expand the screenshot, I get the text of the link, followed by what appears to be the embedded png file ` <img id="img_0" style="display: none" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABHUAAE1TCAIAAAC7lrj7AAAgAElEQVR4nOzde1iTd543/ etc.` So unless I can change how the image is embedded, sounding like I need to send it as an attachment? – Chuck van der Linden Jul 15 '13 at 20:24

Oh, I got it. I made a typo:

cat <<'EOF' - Audit_Results.html | mutt -H -

Note the extra - argument to cat. Without it, the standard input of cat is redirected from the here document, but that isn't useful, since cat isn't reading its standard input. The command was equivalent to cat Audit_Results.html, so mutt didn't receive any headers and complained that it had no indication of any recipient (no To:). In the corrected snippet, cat has two arguments: - (meaning standard input) and Audit_Results.html, so mutt receives the headers followed by the payload.

As for the content type, it turns out that Mutt ignores the supplied Content-Type header and overrides it with the content_type option, so you need to set the content_type option on the command line:

cat <<'EOF' - Audit_Results.html | mutt -e 'set content_type=text/html' -H -
To: cvanderlinden@xxxxxx.com
Subject: "test sending html mail"

If you're going that route, you might as well pass other headers via command line options.

mutt -e 'set content_type=text/html' -s 'test sending html mail' cvanderlinden@xxxxxx.com <Audit_Results.html

Not all mail readers support CS and Javascript. You may need to tweak the way the HTML is generated if you need to accommodate some restricted readers. This includes webmail readers, which need to disable most active features so that they won't conflict with the webmail application.

| improve this answer | |
  • That sends, but the body of the mail is the raw HTML, I'm seeing all the tags, embedded CSS, etc – Chuck van der Linden Jul 15 '13 at 20:19
  • 1
    @ChuckvanderLinden Oh, mutt is overriding the Content-Type header for some reason. I'll investigate. – Gilles 'SO- stop being evil' Jul 15 '13 at 20:27
  • Thanks for looking into that, so basically we end up at the same place as what @bahamat suggested. Wish I could give you both credit for the 'right answer' – Chuck van der Linden Jul 15 '13 at 20:50

Both answers above worked for sending the HTML as the body of the message, in html format.

Unfortunately the contents of a cucumber HTML report are a bit too sophisticated for most mail readers, so the rendering of the report is less than stellar, and the embedded graphics are lost entirely.

So in terms of using Mutt what I ended up doing was using the following to send the HTML as an attachment

echo "your audit results are attached" | mutt -s "Your audit results" -a Audit_Results.html -- cvanderlinden@example.com 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.