Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

We use mutt to send out emails.

mutt -s "Test" -e "Content-Type: text/html" test@example.com < message.html

We send out our email updates in HTML format. We would like to send emails as multi-part containing both a text version and an html version.

  1. How do we create such a multipart message in Linux when the email subject, and HTML and text versions of the email body are given?
  2. Can we use mutt to send the multipart email created in step 1, from the linux prompt?

Envirnonment: RedHat Enterprise Linux 5, mutt

share|improve this question

migrated from stackoverflow.com May 21 '11 at 14:10

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer

up vote 5 down vote accepted

How do we create such a multipart message in Linux when the email subject, and HTML and text versions of the email body are given?

Create a message of type multipart/alternative as documented in RFC 2046:

From: Example Company <news@example.com>
To: Joe User <joe.u@example.net>
Date: Sat, 21 May 2011 17:40:11 +0300
Subject: Multipart message example
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=asdfghjkl

--asdfghjkl
Content-Type: text/plain; charset=utf-8

Hello everyone!

--asdfghjkl
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<body>
<p>Hello everyone!</p>
</body>

--asdfghjkl--

See RFC 2046 and RFC 5322 for the exact syntax.

Can we use mutt to send the multipart email created in step 1, from the linux prompt?

If you find a way to set the right Content-Type header. (In your example, you are using -e, but mutt uses -e for different purposes. Even -e "my_hdr Content-Type: ..." leaves the original text/plain header intact.)

It's better to send generated mail directly through sendmail. You'll have to create the headers yourself – see the example; use strftime("%a, %d %b %Y %T %z") for Date and a string of random alphanumeric characters for the boundary. Then pipe the prepared message, including headers, to sendmail -i -t:

sendmail -i -t < above-example.txt

(The -t option means "get recipients from the To: line"; you can alternatively use sendmail -i joe.u@example.net)

share|improve this answer
    
Thanks for the great answer, grawity! Thanks also for explaining in detail how to compose a multipart email. :) –  user544192 May 23 '11 at 21:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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